This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.js
66 lines (60 loc) · 2.14 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
61
62
63
64
65
66
import { createBareServer } from "@tomphttp/bare-server-node";
import express from "express";
import { createServer } from "node:http";
import path from "path";
import fs from "fs";
import { fileURLToPath } from "url";
import wisp from "wisp-server-node";
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
import { baremuxPath } from "@mercuryworkshop/bare-mux";
import "ws";
console.log("Starting Terbium...");
const app = express();
const bare = createBareServer('/bare/')
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(
express.static("src", {
setHeaders: (res, path) => {
if (path.endsWith(".cjs")) {
res.setHeader("Content-Type", "text/javascript");
}
}
})
);
app.use("/baremux/", express.static(baremuxPath));
app.use("/libcurl/", express.static(libcurlPath));
const server = createServer();
server.on("request", (req, res) => {
if (bare.shouldRoute(req)) {
bare.routeRequest(req, res);
} else {
app(req, res);
}
});
server.on("upgrade", (req, socket, head) => {
if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
} else if (req.url.endsWith("/bare")) {
bare.routeUpgrade(req, socket, head);
}
});
const port = parseInt(process.env.PORT || "8080");
const manifest = fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8');
const { version } = JSON.parse(manifest);
server.listen(port, () => {
console.log(`
\x1b[38;2;50;174;98m@@@@@@@@@@@@@@~ B@@@@@@@@#G?.
\x1b[38;2;50;174;98mB###&@@@@&####^ #@@@&PPPB@@@G.
\x1b[38;2;50;174;98m .. ~@@@@J .. .#@@@P ~&@@@^ \x1b[38;2;60;195;240mWelcome to Terbulence v${version}
\x1b[38;2;50;174;98m^@@@@? .#@@@@###&@@&7
\x1b[38;2;50;174;98m^@@@@? .#@@@#555P&@@B7 \x1b[38;2;182;182;182mTerbulence is running on ${port}
\x1b[38;2;50;174;98m^@@@@? .#@@@P G@@@@ \x1b[38;2;182;182;182mAny problems you encounter let us know!
\x1b[38;2;50;174;98m^@@@@? .#@@@&GGG#@@@@Y
\x1b[38;2;50;174;98m^&@@@? B@@@@@@@@&B5~
`);
});
process.on("SIGINT", () => {
console.log("\x1b[0m");
process.exit();
});