forked from dazacode/Lunanom
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.mjs
36 lines (29 loc) · 1 KB
/
index.mjs
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
import Server from './bare/Server.mjs';
import { readFileSync } from 'fs';
import http from 'http';
import nodeStatic from 'node-static';
import os from 'os';
const bare = new Server('/bare/', '');
const serve = new nodeStatic.Server('public/');
const server = http.createServer();
server.on('request', (request, response) => {
if (bare.route_request(request, response)) return true;
serve.serve(request, response);
});
server.on('upgrade', (req, socket, head) => {
if (bare.route_upgrade(req, socket, head)) return;
socket.end();
});
server.listen(process.env.PORT || 80);
server.on("listening", () => {
const address = server.address();
// by default we are listening on 0.0.0.0 (every interface)
// we just need to list a few
console.log("Listening on:");
console.log(`\thttp://localhost:${address.port}`);
console.log(`\thttp://${os.hostname()}:${address.port}`);
console.log(
`\thttp://${address.family === "IPv6" ? `[${address.address}]` : address.address
}:${address.port}`
);
});