@@ -362,35 +362,76 @@ class RealBreastDensityAPI {
362362 const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 5000 ) ;
363363
364364 try {
365- const requestHeaders = {
366- ...this . defaultHeaders ,
367- // Remove Content-Type to let browser set it automatically for FormData
368- // This prevents multipart/form-data boundary issues
369- } ;
370- delete requestHeaders [ 'Content-Type' ] ;
365+ console . log ( '🔄 Testing CORS connectivity...' ) ;
366+ console . log ( '📍 URL:' , `${ this . baseUrl } /health` ) ;
367+
368+ // Prepare headers safely
369+ let requestHeaders = { } ;
370+
371+ // Only add Authorization if it exists and we need it
372+ // For health check, we typically don't need auth
373+ if ( this . defaultHeaders && this . includeAuthInHealthCheck ) {
374+ requestHeaders = { ...this . defaultHeaders } ;
375+ // Remove Content-Type as it's not needed for GET requests
376+ delete requestHeaders [ 'Content-Type' ] ;
377+ } else {
378+ // Minimal headers for health check
379+ requestHeaders = {
380+ 'Accept' : 'application/json'
381+ } ;
382+ }
371383
372- const response = await fetch ( `${ this . baseUrl } /health` , {
384+ console . log ( '📋 Request headers:' , requestHeaders ) ;
385+
386+ const fetchOptions = {
373387 method : 'GET' ,
374388 headers : requestHeaders ,
375389 signal : controller . signal ,
376390 mode : 'cors' ,
377- credentials : 'include' ,
391+ credentials : 'omit' , // Change from 'include' to 'omit' to avoid credential issues
378392 referrerPolicy : 'strict-origin-when-cross-origin'
379- } ) ;
393+ } ;
394+
395+ console . log ( '⚙️ Fetch options:' , fetchOptions ) ;
396+
397+ const response = await fetch ( `${ this . baseUrl } /health` , fetchOptions ) ;
380398
381399 clearTimeout ( timeoutId ) ;
382400
383401 console . log ( `✅ CORS connectivity test passed: ${ response . status } ` ) ;
402+ console . log ( '📊 Response details:' , {
403+ status : response . status ,
404+ statusText : response . statusText ,
405+ headers : Object . fromEntries ( response . headers . entries ( ) ) ,
406+ url : response . url
407+ } ) ;
408+
384409 this . sslErrorDetected = false ;
385410
386411 return {
387412 success : true ,
388413 status : response . status ,
389414 statusText : response . statusText ,
390415 available : response . status < 500 ,
391- strategy : 'cors'
416+ strategy : 'cors' ,
417+ headers : Object . fromEntries ( response . headers . entries ( ) )
392418 } ;
419+
420+ } catch ( error ) {
421+ clearTimeout ( timeoutId ) ;
422+
423+ console . error ( '❌ CORS connectivity test failed:' , error ) ;
424+ console . error ( '📋 Error details:' , {
425+ name : error . name ,
426+ message : error . message ,
427+ stack : error . stack ?. substring ( 0 , 200 )
428+ } ) ;
429+
430+ // Re-throw the error to be handled by the calling function
431+ throw error ;
432+
393433 } finally {
434+ // Ensure timeout is always cleared
394435 clearTimeout ( timeoutId ) ;
395436 }
396437 }
0 commit comments