-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserve.js
38 lines (34 loc) · 921 Bytes
/
serve.js
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
//
// This is what's hosting when you run `npm run start:dev`
//
const http = require('http')
const fs = require('fs')
const server = http.createServer((req, res) => {
// if root is requested, send the index page. Otherwise
// send what's requested.
if (req.url === '/') {
fs.readFile(__dirname + '/index.html', function (err,data) {
if (err) {
res.writeHead(404)
res.end(JSON.stringify(err))
return
}
res.writeHead(200)
res.end(data)
})
} else {
fs.readFile(__dirname + req.url, function (err,data) {
if (err) {
res.writeHead(404)
res.end(JSON.stringify(err))
return
}
res.writeHead(200)
res.end(data)
})
}
})
const port = process.env.PORT || 8000
server.listen(port, () => {
console.log(`##### network code is now being served, navigate to http://localhost:${port} to see network stats`)
})