forked from cs4241-21a/a1-gettingstarted
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (40 loc) · 1.13 KB
/
Copy pathserver.js
File metadata and controls
42 lines (40 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
console.log("Server starting up")
const http = require('http'),
fs = require('fs'),
port = 3000
console.log("Imported packages")
const server = http.createServer( function( request,response ) {
console.log("New request for " + request.url)
switch( request.url ) {
case '/':
sendFile( response, 'index.html' )
break
case '/index.html':
sendFile( response, 'index.html' )
break
case '/style.css':
sendFile(response, 'style.css')
break
case '/classnotes/':
sendFile(response, 'classnotes/index.html')
break
case '/classnotes/8-26-21':
sendFile(response, 'classnotes/8-26-21.html')
break
case '/classnotes/8-30-21':
sendFile(response, 'classnotes/8-30-21.html')
break
case '/classnotes/9-2-21':
sendFile(response, 'classnotes/9-2-21.html')
break
default:
response.end( '404 Error: File Not Found' )
}
})
server.listen( process.env.PORT || port )
const sendFile = function( response, filename ) {
fs.readFile( filename, function( err, content ) {
file = content
response.end( content, 'utf-8' )
})
}