@@ -6,74 +6,63 @@ const serverport = process.env.PORT || 8080
66
77const server = http . createServer ( async ( request :any , response :any ) => {
88
9- //let result = fs.readFileSync('./test/index.html')
10-
11- //res.statusCode = 200
12-
13- //res.setHeader('Content-Type','application/xml')
14-
15- //res.setHeader('Content-Type','text/plain')
16-
17- //res.setHeader('Access-Control-Allow-Origin','*')
18-
19- //res.setHeader('Content-Type','text/html')
20-
21- //res.end(result)
22-
23- //console.log('request starting...');
24-
259 var filePath = '.' + request . url ;
26- if ( filePath == './' )
27- filePath = './index.html' ;
10+ if ( filePath == './' ) {
11+ const html = '<a href="test/umd.html">umd</a><br><a href="test/esm.html">esm</a>'
12+ response . statusCode = 200
13+ response . setHeader ( 'Content-Type' , 'text/html' )
14+ response . end ( html )
15+ } else {
2816
29- var extname = path . extname ( filePath ) ;
30- var contentType = 'text/html' ;
31- switch ( extname ) {
32- case '.html' :
33- contentType = 'text/html' ;
34- break ;
35- case '.js' :
36- contentType = 'text/javascript' ;
37- break ;
38- case '.css' :
39- contentType = 'text/css' ;
40- break ;
41- case '.json' :
42- contentType = 'application/json' ;
43- break ;
44- case '.png' :
45- contentType = 'image/png' ;
46- break ;
47- case '.jpg' :
48- contentType = 'image/jpg' ;
49- break ;
50- case '.wav' :
51- contentType = 'audio/wav' ;
52- break ;
53- default :
54- filePath += filePath + '.js' ;
55- contentType = 'text/javascript' ;
56- }
17+ var extname = path . extname ( filePath ) ;
18+ var contentType = 'text/html' ;
19+ switch ( extname ) {
20+ case '.html' :
21+ contentType = 'text/html' ;
22+ break ;
23+ case '.js' :
24+ contentType = 'text/javascript' ;
25+ break ;
26+ case '.css' :
27+ contentType = 'text/css' ;
28+ break ;
29+ case '.json' :
30+ contentType = 'application/json' ;
31+ break ;
32+ case '.png' :
33+ contentType = 'image/png' ;
34+ break ;
35+ case '.jpg' :
36+ contentType = 'image/jpg' ;
37+ break ;
38+ case '.wav' :
39+ contentType = 'audio/wav' ;
40+ break ;
41+ default :
42+ filePath += filePath + '.js' ;
43+ contentType = 'text/javascript' ;
44+ }
5745
58- fs . readFile ( filePath , function ( error :any , content :any ) {
59- if ( error ) {
60- if ( error . code == 'ENOENT' ) {
61- fs . readFile ( './404.html' , function ( error :any , content :any ) {
62- response . writeHead ( 200 , { 'Content-Type' : contentType } ) ;
63- response . end ( content , 'utf-8' ) ;
64- } ) ;
65- }
66- else {
67- response . writeHead ( 500 ) ;
68- response . end ( 'Sorry, check with the site admin for error: ' + error . code + ' ..\n' ) ;
69- response . end ( ) ;
70- }
71- }
72- else {
73- response . writeHead ( 200 , { 'Content-Type' : contentType } ) ;
74- response . end ( content , 'utf-8' ) ;
75- }
76- } ) ;
46+ fs . readFile ( filePath , function ( error :any , content :any ) {
47+ if ( error ) {
48+ if ( error . code == 'ENOENT' ) {
49+ fs . readFile ( './404.html' , function ( content :any ) {
50+ response . writeHead ( 200 , { 'Content-Type' : contentType } ) ;
51+ response . end ( content , 'utf-8' ) ;
52+ } ) ;
53+ }
54+ else {
55+ response . writeHead ( 500 ) ;
56+ response . end ( 'Sorry, check with the site admin for error: ' + error . code + ' ..\n' ) ;
57+ response . end ( ) ;
58+ }
59+ }
60+ else {
61+ response . writeHead ( 200 , { 'Content-Type' : contentType } ) ;
62+ response . end ( content , 'utf-8' ) ;
63+ }
64+ } ) ;
65+ }
7766
7867} )
7968
0 commit comments