File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,22 +28,53 @@ const requestListener = function (req, res) {
2828 if ( req . url === "/test" ) {
2929 fs . readFile ( "templates/rick.html" , function ( err , data ) {
3030 if ( err ) {
31- res . writeHead ( 404 ) ;
32- res . end ( JSON . stringify ( err ) ) ;
31+ res . writeHead ( 203 ) ;
32+ res . end ( "<html><body><b>internal error</b></body></html>" + JSON . stringify ( err ) ) ;
3333 return ;
3434 }
3535 res . writeHead ( 200 ) ;
3636 res . end ( data ) ;
3737 } ) ;
3838 } else if ( req . url === "/" ) {
39-
40- } else {
39+ //template stuff
40+ res . writeHead ( 200 )
41+ res . end ( "N/A" )
42+ } else if ( req . url . includes ( "/../" ) ) {
43+ fs . readFile ( "templates/500.html" , function ( err , data ) {
44+ if ( err ) {
45+ res . writeHead ( 203 ) ;
46+ res . end ( "<html><body><b>internal error</b></body></html>" + JSON . stringify ( err ) ) ;
47+ return ;
48+ }
49+ res . writeHead ( 200 ) ;
50+ res . end ( data ) ;
51+ } ) ;
52+
53+ } else {
4154 fs . readFile ( "static" + req . url , function ( err , data ) {
4255 if ( err ) {
43- res . writeHead ( 404 ) ;
56+
57+ if ( err . code == "ENOENT" ) {
58+
59+ fs . readFile ( "templates/404.html" , function ( err , data ) {
60+ if ( err ) {
61+ res . writeHead ( 203 ) ;
62+ res . end ( "<html><body><b>internal error</b></body></html>" + JSON . stringify ( err ) ) ;
63+ return ;
64+ }
65+
66+ res . writeHead ( 404 ) ;
67+ res . end ( data ) ;
68+ return ;
69+ } )
70+ return ;
71+ }
72+
73+ res . writeHead ( 203 ) ;
4474 res . end ( JSON . stringify ( err ) ) ;
4575 return ;
4676 }
77+
4778 res . writeHead ( 200 ) ;
4879 res . end ( data ) ;
4980 } ) ;
Original file line number Diff line number Diff line change 1+ < html >
2+ < body >
3+ < h1 >
4+ 404.
5+ </ h1 >
6+ < h2 >
7+ < i > Unexisting things cannot be found</ i >
8+ </ h2 >
9+ </ body >
10+ </ html >
Original file line number Diff line number Diff line change 1+ < html >
2+ < body >
3+ < h1 >
4+ 500
5+ </ h1 >
6+ < h2 >
7+ You asked for something dangerous
8+ </ h2 >
9+ </ body >
10+ </ html >
You can’t perform that action at this time.
0 commit comments