-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.ts
More file actions
43 lines (36 loc) · 1.18 KB
/
index.ts
File metadata and controls
43 lines (36 loc) · 1.18 KB
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
import { spawn } from "node:child_process";
import { createServer, Server } from "node:http";
import { Socket } from "node:net";
import express, { Request, Response, Express } from "express";
import { server as wisp, logging } from "@mercuryworkshop/wisp-js/server";
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
import { libcurlPath } from "@mercuryworkshop/libcurl-transport";
spawn("pnpm", ["rspack", "-w"], {
detached: true,
});
logging.set_level(logging.ERROR);
const port: number = Number(process.env.PORT) || 6000;
const server: Server = createServer();
const app: Express = express();
app.use("/eclipse/", express.static("dist"));
app.use(
express.static("public", {
index: "index.html",
extensions: ["html"],
})
);
app.use("/baremux/", express.static(baremuxPath));
app.use("/libcurl/", express.static(libcurlPath));
server.on("request", (req: Request, res: Response) => {
app(req, res);
});
server.on("upgrade", (req: Request, socket: Socket, head: Buffer) => {
if (req.url && req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
} else {
socket.end();
}
});
server.listen(port, () => {
console.log(`Eclipse listening on port ${port}`);
});