Attempt four of making the webclient work with message history.
This commit is contained in:
parent
9e8158a5c0
commit
72c6735cba
1 changed files with 10 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue