-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
45 lines (38 loc) · 1.38 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
import express from "express";
import { createServer } from "http";
import { fileURLToPath } from "url";
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
import { join } from "path";
const port = 8080;
const publicPath = fileURLToPath(new URL("./public/", import.meta.url));
const app = express();
const server = createServer();
app.use(express.static(publicPath, { maxAge: 604800000 })); //1 week
app.use("/epoxy/", express.static(epoxyPath));
app.use("/libcurl/", express.static(libcurlPath));
app.use("/baremux/", express.static(baremuxPath));
app.use("/uv/", express.static(uvPath));
app.use((req, res) => {
res.status(404);
res.sendFile(join(publicPath, "404.html"));
});
server.on("request", (req, res) => {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
app(req, res);
});
server.on("upgrade", (req, socket, head) => {
if (req.url.endsWith("/wisp/"))
wisp.routeRequest(req, socket, head);
else socket.end();
});
server.on("listening", () => {
const address = server.address();
console.log(
"\n\n\n\x1b[35m\x1b[2m\x1b[1m%s\x1b[0m\n",
`Acceleration has started!\nRunning on port ${address.port}`,
);
});
server.listen(port);