File tree Expand file tree Collapse file tree 1 file changed +5
-10
lines changed
blog/25-07-24/http-server/ex Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Original file line number Diff line number Diff line change 1616
1717
1818 function request ( req , res ) {
19-
19+ console . log ( req . method , req . url ) ;
2020 if ( cors ( req , res ) ) {
2121 return ;
2222 }
6767 if ( req . method != 'OPTIONS' ) {
6868 return ;
6969 }
70-
70+ console . log ( 'cors' ) ;
7171 res . writeHead ( 200 ) ;
7272 res . end ( ) ;
7373 return true ;
8686
8787
8888 function badrequest ( req , res ) {
89-
89+ console . log ( 'bad request' ) ;
9090 res . writeHead ( 400 ) ;
9191 res . end ( `${ req . url } bad request` ) ;
9292
9393 } //bad
9494
9595
9696 function notfound ( req , res ) {
97-
97+ console . log ( 'not found' ) ;
9898 res . writeHead ( 400 ) ;
9999 res . end ( `${ req . url } not found` ) ;
100100
165165
166166 function mime ( fn ) {
167167
168- var ext = fn ;
169- var i = fn . lastIndexOf ( '.' ) ;
170- if ( i != - 1 ) {
171- ext = fn . slice ( i + 1 ) ;
172- }
173-
168+ var ext = fn . split ( '.' ) . at ( - 1 ) ;
174169 switch ( ext ) {
175170
176171 case 'html' : return 'text/html' ;
You can’t perform that action at this time.
0 commit comments