forked from cs4241-18a/a1-gettingstarted
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
45 lines (38 loc) · 931 Bytes
/
server.js
File metadata and controls
45 lines (38 loc) · 931 Bytes
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
43
44
45
var http = require('http')
, fs = require('fs')
, url = require('url')
, port = 8080;
var server = http.createServer (function (req, res) {
var uri = url.parse(req.url)
switch( uri.pathname ) {
case '/':
sendFile(res, 'index.html')
break
case '/index.html':
sendFile(res, 'index.html')
break
case '/bootstrap.css':
sendFile(res, 'bootstrap.css')
break
case '/prof.jpg':
sendFile(res, 'prof.jpg')
break
case '/dnb.jpg':
sendFile(res, 'dnb.jpg')
break
case '/lmi.png':
sendFile(res, 'lmi.png')
break
default:
res.end('404 not found')
}
})
server.listen(process.env.PORT || port);
console.log('listening on 8080')
// subroutines
function sendFile(res, filename) {
fs.readFile(filename, function(error, content) {
res.writeHead(200, {'Content-type': 'text/html'})
res.end(content, 'utf-8')
})
}