-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (36 loc) · 924 Bytes
/
server.js
File metadata and controls
41 lines (36 loc) · 924 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
const os = require('os')
const path = require('path')
const http = require('http');
const ecstatic = require('ecstatic');
const ifaces = os.networkInterfaces()
function print_information(port) {
console.group()
console.log()
for (let info of Object.values(ifaces)) {
for (let { address, internal }
of info) {
console.log(`http://${address}:${port}/ ${internal?'internal':''}`)
}
}
console.log()
console.groupEnd()
}
function run_server(port, callback) {
print_information(port)
callback()
http.createServer(ecstatic({
root: path.join(__dirname, 'public'),
showDir: true,
autoIndex: true,
})).listen(port)
}
module.exports = run_server
if (require.main === module) {
const port = process.env.PORT || 3000
print_information(port)
http.createServer(ecstatic({
root: path.join(__dirname, 'public'),
showDir: true,
autoIndex: true,
})).listen(port);
}