@@ -432,6 +432,13 @@ async function startStudioUIServer(
432432
433433 console . log ( chalk . gray ( ` Serving studio-ui from: ${ studioSourcePath } ` ) ) ;
434434
435+ const indexHtmlPath = path . join ( studioSourcePath , 'index.html' ) ;
436+ if ( ! fs . existsSync ( indexHtmlPath ) ) {
437+ console . error ( chalk . red ( ` ERROR: index.html not found at ${ indexHtmlPath } ` ) ) ;
438+ throw new Error ( `Studio-UI index.html missing at ${ indexHtmlPath } ` ) ;
439+ }
440+ console . log ( chalk . gray ( ` Verified index.html exists at: ${ indexHtmlPath } ` ) ) ;
441+
435442 const serve = serveStatic ( studioSourcePath , {
436443 index : [ 'index.html' ] ,
437444 setHeaders : ( res , path ) => {
@@ -457,10 +464,12 @@ async function startStudioUIServer(
457464 try {
458465 await new Promise < void > ( ( resolve , reject ) => {
459466 const server = http . createServer ( ( req , res ) => {
460- const url = new URL ( req . url || '/' , `http://${ req . headers . host } ` ) ;
467+ try {
468+ console . log ( chalk . gray ( ` [Studio HTTP] ${ req . method } ${ req . url } from ${ req . socket . remoteAddress } ` ) ) ;
469+ const url = new URL ( req . url || '/' , `http://${ req . headers . host || 'localhost:7174' } ` ) ;
461470
462- // Inject config for index.html
463- if ( url . pathname === '/' || url . pathname === '/index.html' ) {
471+ // Inject config for index.html
472+ if ( url . pathname === '/' || url . pathname === '/index.html' ) {
464473 const indexPath = path . join ( studioSourcePath , 'index.html' ) ;
465474 let html = fs . readFileSync ( indexPath , 'utf8' ) ;
466475 const connectionScript = `
@@ -517,14 +526,31 @@ async function startStudioUIServer(
517526 res . setHeader ( 'Content-Type' , 'text/html' ) ;
518527 res . end ( html ) ;
519528 } ) ;
529+ } catch ( error ) {
530+ console . error ( chalk . red ( ` [Studio HTTP] Error handling request: ${ error } ` ) ) ;
531+ res . statusCode = 500 ;
532+ res . end ( 'Internal Server Error' ) ;
533+ }
534+ } ) ;
535+
536+ server . on ( 'listening' , ( ) => {
537+ const addr = server . address ( ) ;
538+ console . log ( chalk . gray ( ` [Studio HTTP] Server listening event fired, address: ${ JSON . stringify ( addr ) } ` ) ) ;
539+ } ) ;
540+
541+ server . on ( 'connection' , ( socket ) => {
542+ console . log ( chalk . gray ( ` [Studio HTTP] New connection from ${ socket . remoteAddress } :${ socket . remotePort } ` ) ) ;
520543 } ) ;
521544
522545 server . listen ( port , '0.0.0.0' , ( ) => {
523546 studioUIServer = server ;
547+ const addr = server . address ( ) ;
548+ console . log ( chalk . gray ( ` [Studio HTTP] Listen callback fired, address: ${ JSON . stringify ( addr ) } ` ) ) ;
524549 resolve ( ) ;
525550 } ) ;
526551
527552 server . on ( 'error' , ( err : NodeJS . ErrnoException ) => {
553+ console . error ( chalk . red ( ` [Studio HTTP] Server error: ${ err . code } - ${ err . message } ` ) ) ;
528554 if ( err . code === 'EADDRINUSE' ) {
529555 reject ( err ) ;
530556 } else {
0 commit comments