Attempt four of making the webclient work with message history.

This commit is contained in:
Charles Descamps 2025-03-28 19:07:36 -07:00
parent 9e8158a5c0
commit 72c6735cba

View file

@ -160,10 +160,17 @@
socket.emit('join', { username: username, chat_room: chatRoom });
// Fetch message history for the initial chat room
fetch(`/get_history?chat_room=${chatRoom}`)
.then(response => response.json())
const serverBaseUrl = `${window.location.protocol}//${window.location.hostname}:5000`;
fetch(`${serverBaseUrl}/get_history?chat_room=${encodeURIComponent(chatRoom)}`)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
if (data.messages) {
if (data.messages && data.messages.length > 0) {
// Display each message in the chat history
data.messages.forEach(message => {
const messageElement = document.createElement('div');
messageElement.textContent = message;