11document . addEventListener ( "DOMContentLoaded" , ( ) => {
2- const SERVER_URL = "https ://vps.unityailab.online:3000" ;
2+ const SERVER_URL = "http ://vps.unityailab.online:3000" ; // Changed to HTTP:3000
33 const USE_LOCAL_FALLBACK = false ; // Set to false for live server interaction
44
55 const sessionListEl = document . getElementById ( "session-list" ) ;
@@ -258,7 +258,6 @@ document.addEventListener("DOMContentLoaded", () => {
258258 }
259259 checkOrGenerateUserId ( ) . then ( ( ) => {
260260 console . log ( "User ID validation complete" ) ;
261- // Force registration every load
262261 const userId = localStorage . getItem ( "uniqueUserId" ) ;
263262 if ( userId ) {
264263 registerUserIdWithServer ( userId ) . catch ( err => {
@@ -286,7 +285,7 @@ document.addEventListener("DOMContentLoaded", () => {
286285 userId = generateRandomId ( ) ;
287286 localStorage . setItem ( "uniqueUserId" , userId ) ;
288287 }
289- await registerUserIdWithServer ( userId ) ; // Always register on load
288+ await registerUserIdWithServer ( userId ) ;
290289 return userId ;
291290 }
292291
@@ -298,6 +297,7 @@ document.addEventListener("DOMContentLoaded", () => {
298297 }
299298 const storedToken = localStorage . getItem ( "userToken" ) ;
300299 try {
300+ console . log ( "Attempting to register userId:" , userId , "with token:" , storedToken ) ;
301301 const response = await fetch ( `${ SERVER_URL } /api/registerUser` , {
302302 method : "POST" ,
303303 headers : { "Content-Type" : "application/json" } ,
@@ -314,15 +314,14 @@ document.addEventListener("DOMContentLoaded", () => {
314314 }
315315
316316 function generateRandomId ( ) {
317- // Ensure 18-20 chars, lowercase alphanumeric
318317 return ( Math . random ( ) . toString ( 36 ) + Date . now ( ) . toString ( 36 ) ) . substr ( 2 , 20 ) . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 ] / g, '' ) ;
319318 }
320319
321320 function startVisitorCountPolling ( ) {
322321 updateVisitorCount ( ) ;
323322 setInterval ( ( ) => {
324323 updateVisitorCount ( ) ;
325- } , 60000 ) ; // 60 seconds
324+ } , 60000 ) ;
326325 }
327326
328327 async function updateVisitorCount ( ) {
@@ -333,6 +332,7 @@ document.addEventListener("DOMContentLoaded", () => {
333332 return ;
334333 }
335334 try {
335+ console . log ( "Fetching visitor count from:" , SERVER_URL + "/api/visitorCount" ) ;
336336 const controller = new AbortController ( ) ;
337337 const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 3000 ) ;
338338 const response = await fetch ( `${ SERVER_URL } /api/visitorCount` , {
0 commit comments