@@ -43,33 +43,34 @@ const server = Bun.serve({
4343 }
4444
4545 const filepath = './' + path . join ( '/' ) ;
46-
4746 try {
4847 const file = Bun . file ( filepath ) ;
4948 if ( await file . exists ( ) ) {
50- console . log ( styleText ( 'greenBright' , `200: Found → '${ filepath } '` ) ) ;
51-
52- if ( / h t m l $ / . test ( filepath ) ) {
49+ console . log (
50+ styleText ( 'greenBright' , `200: Found → '${ file . name } '` ) +
51+ styleText ( 'green' , ` ${ file . type } '` )
52+ ) ;
53+ if ( / ( h t m l | j a v a s c r i p t ) / . test ( file . type ) ) {
5354 const content : string = await file . text ( ) ;
54- return new Response ( replaceCDNPath ( content ) , { headers : { 'content-type' : 'text/html' } } ) ;
55+ return new Response ( replaceCDNPath ( content ) , { headers : { 'content-type' : file . type } } ) ;
5556 } else {
5657 return new Response ( file ) ;
5758 }
59+ } else {
60+ console . log ( styleText ( 'redBright' , `404: Not Found → '${ filepath } '` ) ) ;
61+ return new Response ( 'Not Found' , { status : 404 } ) ;
5862 }
5963 } catch ( error ) {
60- // Handle potential errors during file access
61- console . error ( `Error serving file: ${ filepath } ` , error ) ;
64+ console . log ( styleText ( 'redBright' , `500: Server Error → '${ filepath } '` ) ) ;
65+ console . error ( error ) ;
66+ return new Response ( 'Internal Server Error' , { status : 500 } ) ;
6267 }
63-
64- // If file not found or error, return 404
65- console . log ( styleText ( 'redBright' , `404: Not Found → '${ filepath } '` ) ) ;
66- return new Response ( 'Not Found' , { status : 404 } ) ;
6768 }
6869} ) ;
6970
7071console . log ( '' ) ;
7172console . log ( styleText ( [ 'blue' , 'bold' ] , `Bun v${ Bun . version } ` ) ) ;
72- console . log ( styleText ( 'cyanBright' , `Serving: [' docs/*', ' dist/*'] ` ) ) ;
73+ console . log ( styleText ( 'cyanBright' , `Serving: docs/*, dist/*` ) ) ;
7374console . log ( styleText ( 'cyanBright' , `Listening: ${ server . url } ` ) ) ;
7475console . log ( styleText ( [ 'whiteBright' , 'bold' ] , `Ctrl-C to stop` ) ) ;
7576console . log ( '' ) ;
0 commit comments