forked from TerbiumOS/webOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (48 loc) · 1.76 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
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 "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("static"));
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("6969");
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 Legacy Terbium v${version}
\x1b[38;2;50;174;98m^@@@@? .#@@@@###&@@&7
\x1b[38;2;50;174;98m^@@@@? .#@@@#555P&@@B7 \x1b[38;2;182;182;182mLegacy Terbium 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();
});