forked from Dragon-Gaming-devs/scramjet
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdevserver.ts
More file actions
90 lines (76 loc) · 2.47 KB
/
Copy pathdevserver.ts
File metadata and controls
90 lines (76 loc) · 2.47 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { createServer } from "vite";
import fs from "node:fs/promises";
import { stdout } from "node:process";
import chalk from "chalk";
import { execSync } from "node:child_process";
import http from "node:http";
import path from "node:path";
import { createReadStream } from "node:fs";
import rspackConfig from "./rspack.config.ts";
import { server as wisp } from "@mercuryworkshop/wisp-js/server";
import {
black,
normalizeWebsocketUrl,
logSuccess,
printBanner,
resetSuccessLog,
runRspack,
warnOnUrlEscape,
} from "./devlib.ts";
const image = await fs.readFile("./assets/scramjet-mini-noalpha.png");
const commit = execSync("git rev-parse --short HEAD", {
encoding: "utf-8",
}).replace(/\r?\n|\r/g, "");
const branch = execSync("git rev-parse --abbrev-ref HEAD", {
encoding: "utf-8",
}).replace(/\r?\n|\r/g, "");
const packagejson = JSON.parse(await fs.readFile("./package.json", "utf-8"));
const version = packagejson.version;
const DEMO_PORT = process.env.DEMO_PORT || 4141;
const WISP_PORT = process.env.WISP_PORT || 4142;
if (process.env.VITE_WISP_URL) {
process.env.VITE_WISP_URL = normalizeWebsocketUrl(process.env.VITE_WISP_URL);
} else {
process.env.VITE_WISP_URL = `ws://localhost:${WISP_PORT}/`;
}
const wispserver = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("wisp server js rewrite");
});
wisp.options.allow_private_ips = true;
wisp.options.allow_loopback_ips = true;
wispserver.on("upgrade", (req, socket, head) => {
wisp.routeRequest(req, socket, head);
});
wispserver.listen(Number(WISP_PORT));
const server = await createServer({
configFile: "./packages/demo/vite.config.ts",
root: "./packages/demo",
server: {
port: Number(DEMO_PORT),
strictPort: true,
},
});
warnOnUrlEscape(server);
await server.listen();
const accent = (text: string) => chalk.hex("#f1855bff").bold(text);
const highlight = (text: string) => chalk.hex("#fdd76cff").bold(text);
const urlColor = (text: string) => chalk.hex("#64DFDF").underline(text);
const note = (text: string) => chalk.hex("#CDB4DB")(text);
const connector = chalk.hex("#8D99AE").dim("@");
const lines = [
black()(`${highlight("SCRAMJET DEV SERVER")}`),
black()(
`${accent("demo")} ${connector} ${urlColor(
`http://localhost:${DEMO_PORT}/`
)}`
),
black()(
`${accent("wisp")} ${connector} ${urlColor(
process.env.VITE_WISP_URL ?? ""
)}`
),
black()(chalk.dim(`[${branch}] ${commit} scramjet/${version}`)),
];
printBanner(image, lines);
runRspack(rspackConfig);