Skip to content

Commit deace96

Browse files
authored
Added Scramjet #1194
Adding Scramjet support to Interstellar
2 parents e200482 + 140c02a commit deace96

19 files changed

Lines changed: 946 additions & 48 deletions

index.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import cookieParser from "cookie-parser";
77
import cors from "cors";
88
import express from "express";
99
import basicAuth from "express-basic-auth";
10+
import bareMuxNode from "@mercuryworkshop/bare-mux/node";
11+
import { server as wisp } from "@mercuryworkshop/wisp-js/server";
1012
import mime from "mime";
1113
import fetch from "node-fetch";
1214
// import { setupMasqr } from "./Masqr.js";
@@ -18,10 +20,21 @@ const __dirname = process.cwd();
1820
const server = http.createServer();
1921
const app = express();
2022
const bareServer = createBareServer("/ca/");
23+
const { baremuxPath } = bareMuxNode;
24+
const epoxyDistPath = path.join(
25+
__dirname,
26+
"node_modules",
27+
"@mercuryworkshop",
28+
"epoxy-transport",
29+
"dist",
30+
);
2131
const PORT = process.env.PORT || 8080;
2232
const cache = new Map();
2333
const CACHE_TTL = 30 * 24 * 60 * 60 * 1000; // Cache for 30 Days
2434

35+
wisp.options.allow_loopback_ips = true;
36+
wisp.options.allow_private_ips = true;
37+
2538
if (config.challenge !== false) {
2639
console.log(chalk.green("🔒 Password protection is enabled! Listing logins below"));
2740
// biome-ignore lint: idk
@@ -90,8 +103,21 @@ app.use(express.urlencoded({ extended: true }));
90103
setupMasqr(app);
91104
} */
92105

106+
const transportStaticOptions = {
107+
setHeaders: (res, filePath) => {
108+
const ext = path.extname(filePath);
109+
if (ext === ".mjs" || ext === ".js") {
110+
res.type("text/javascript");
111+
} else if (ext === ".wasm") {
112+
res.type("application/wasm");
113+
}
114+
},
115+
};
116+
93117
app.use(express.static(path.join(__dirname, "static")));
94118
app.use("/ca", cors({ origin: true }));
119+
app.use("/bm", express.static(baremuxPath, transportStaticOptions));
120+
app.use("/ep", express.static(epoxyDistPath, transportStaticOptions));
95121

96122
const routes = [
97123
{ path: "/b", file: "apps.html" },
@@ -130,7 +156,7 @@ server.on("upgrade", (req, socket, head) => {
130156
if (bareServer.shouldRoute(req)) {
131157
bareServer.routeUpgrade(req, socket, head);
132158
} else {
133-
socket.end();
159+
wisp.routeRequest(req, socket, head);
134160
}
135161
});
136162

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"author": "InterstellarNetwork",
1616
"license": "GPL-3.0-or-later",
1717
"dependencies": {
18+
"@mercuryworkshop/bare-mux": "^2.1.8",
19+
"@mercuryworkshop/epoxy-transport": "2.1.28",
20+
"@mercuryworkshop/scramjet": "^1.0.2",
21+
"@mercuryworkshop/wisp-js": "^0.4.1",
1822
"@nebula-services/bare-server-node": "^2.0.4",
1923
"chalk": "^5.4.1",
2024
"cookie-parser": "^1.4.7",
@@ -28,5 +32,5 @@
2832
"devDependencies": {
2933
"@biomejs/biome": "2.2.2"
3034
},
31-
"packageManager": "pnpm@9.10.0"
35+
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
3236
}

0 commit comments

Comments
 (0)