-
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathserver.js
More file actions
26 lines (21 loc) · 706 Bytes
/
server.js
File metadata and controls
26 lines (21 loc) · 706 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
import http from 'http'
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// Load index.html into memory
const indexHtml = fs.readFileSync(path.join(__dirname, 'index.html'))
const contentLength = Buffer.byteLength(indexHtml)
const HOST = process.env.HOST || '127.0.0.1'
const PORT = process.env.PORT || '8080'
const server = http.createServer((req, res) => {
res.writeHead(200, {
'Content-Type': 'text/html',
'Content-Length': contentLength,
})
res.end(indexHtml)
})
server.listen(PORT, HOST, () => {
console.log(`Server running at http://${HOST}:${PORT}/`)
})