forked from xNovaLabs/Xen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
48 lines (36 loc) · 1.01 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
37
38
39
40
41
42
43
44
45
46
47
48
import http from 'node:http';
import { createBareServer } from '@tomphttp/bare-server-node';
import express from 'express';
import { hostname } from "node:os";
const httpServer = http.createServer();
const app = express();
app.use(express.static("src"));
const bareServer = createBareServer('/y/');
httpServer.on('request', (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res);
} else {
app(req, res);
}
});
httpServer.on('upgrade', (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});
httpServer.on('listening', () => {
const address = httpServer.address();
console.log("Listening on:");
console.log(`\thttp://localhost:${address.port}`);
console.log(`\thttp://${hostname()}:${address.port}`);
console.log(
`\thttp://${
address.family === "IPv6" ? `[${address.address}]` : address.address
}:${address.port}`
);
});
httpServer.listen({
port: 8080,
});