Commit c90ac0e 1 parent 0e596ed commit c90ac0e Copy full SHA for c90ac0e
File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ < h1 > 404!!!!</ h1 >
2
+ < div > file not found</ div >
Original file line number Diff line number Diff line change
1
+ var http = require ( 'http' )
2
+ var fs = require ( 'fs' )
3
+ var count = 0
4
+ var server = http . createServer ( function ( req , res ) {
5
+ console . log ( req . method , req . url )
6
+ if ( req . method === 'GET' && req . url === '/' ) {
7
+ res . setHeader ( 'content-type' , 'text/html' )
8
+ res . end ( `<h1>HOWDY</h1>
9
+ <div>you are the ${ count ++ } th visitor</div>
10
+ <div>sign my guestbook</div>
11
+ ` )
12
+ } else {
13
+ fs . readFile ( '404.html' , function ( err , src ) {
14
+ if ( err ) {
15
+ res . statusCode = 500
16
+ res . setHeader ( 'content-type' , 'text/plain' )
17
+ res . end ( err + '\n' )
18
+ } else {
19
+ res . statusCode = 404
20
+ res . setHeader ( 'content-type' , 'text/html' )
21
+ res . end ( src )
22
+ }
23
+ } )
24
+ }
25
+ } )
26
+ server . listen ( 3000 )
You can’t perform that action at this time.
0 commit comments