1- const http = require ( 'http' ) ;
2- const fs = require ( 'fs' ) ;
3- const path = require ( 'path' ) ;
1+ const http = require ( 'node: http' ) ;
2+ const fs = require ( 'node: fs' ) ;
3+ const path = require ( 'node: path' ) ;
44
55const server = http . createServer ( ( req , res ) => {
66 // Add CORS headers
@@ -9,24 +9,25 @@ const server = http.createServer((req, res) => {
99 res . setHeader ( 'Access-Control-Allow-Headers' , 'Content-Type' ) ;
1010
1111 let filePath = path . join ( __dirname , 'storybook-static' , req . url === '/' ? 'index.html' : req . url ) ;
12-
12+
1313 // If file doesn't exist, serve index.html for SPA routing
1414 if ( ! fs . existsSync ( filePath ) ) {
1515 filePath = path . join ( __dirname , 'storybook-static' , 'index.html' ) ;
1616 }
17-
17+
1818 const ext = path . extname ( filePath ) ;
19- const contentType = {
20- '.html' : 'text/html' ,
21- '.js' : 'text/javascript' ,
22- '.css' : 'text/css' ,
23- '.json' : 'application/json' ,
24- '.png' : 'image/png' ,
25- '.jpg' : 'image/jpeg' ,
26- '.gif' : 'image/gif' ,
27- '.svg' : 'image/svg+xml'
28- } [ ext ] || 'text/plain' ;
29-
19+ const contentType =
20+ {
21+ '.html' : 'text/html' ,
22+ '.js' : 'text/javascript' ,
23+ '.css' : 'text/css' ,
24+ '.json' : 'application/json' ,
25+ '.png' : 'image/png' ,
26+ '.jpg' : 'image/jpeg' ,
27+ '.gif' : 'image/gif' ,
28+ '.svg' : 'image/svg+xml' ,
29+ } [ ext ] || 'text/plain' ;
30+
3031 fs . readFile ( filePath , ( err , content ) => {
3132 if ( err ) {
3233 console . error ( 'Error reading file:' , filePath , err ) ;
@@ -43,4 +44,3 @@ const PORT = 45678;
4344server . listen ( PORT , ( ) => {
4445 console . log ( `Server running on http://127.0.0.1:${ PORT } ` ) ;
4546} ) ;
46-
0 commit comments