-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
60 lines (49 loc) · 1.61 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import express from "express";
import http from "node:http";
import path from "node:path";
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
import { createBareServer } from '@tomphttp/bare-server-node';
import { uvPath } from '@titaniumnetwork-dev/ultraviolet';
import wisp from "wisp-server-node";
const __dirname = path.resolve();
const server = http.createServer();
const bareServer = createBareServer('/bare/');
const app = express();
const port = 5002;
app.use("/uv-v1/", express.static(uvPath));
app.use("/epoxy", express.static(epoxyPath));
app.use("/baremux/", express.static(baremuxPath));
app.use(express.static(path.join(__dirname, "static")));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "./static/index.html"));
});
app.use((req, res) => {
res.statusCode = 404;
res.sendFile(path.join(__dirname, "./static/404.html"));
});
server.on("request", (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res);
} else app(req, res);
});
server.on("upgrade", (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
} else socket.end();
});
server.on("listening", () => {
console.log(`Modal is running on port ${port}\n\nhttp://localhost:${port}`);
});
process.on("SIGINT", close);
process.on("SIGTERM", close);
function close() {
console.log("Caught SIGTERM, shutting down");
server.close();
process.exit(0);
}
server.listen({
port: port,
});