Skip to content

Commit 0ab60da

Browse files
author
lich2king
committed
scramjet
1 parent c0b7034 commit 0ab60da

24 files changed

Lines changed: 1504 additions & 491 deletions

index.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { bareModulePath } from "@mercuryworkshop/bare-as-module3";
77
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
88
//import { join } from "node:path";
99
import { hostname } from "node:os";
10-
import wisp from "wisp-server-node";
10+
//import wisp from "wisp-server-node";
11+
import { server as wisp, logging } from "@mercuryworkshop/wisp-js/server";
1112

1213
import { createBareServer } from "@tomphttp/bare-server-node";
1314
import cors from "cors";
@@ -19,17 +20,38 @@ import { fileURLToPath } from 'url';
1920

2021
import validator from 'validator';
2122

23+
import { createRequire } from "node:module";
24+
2225

2326
const __filename = fileURLToPath(import.meta.url);
2427
const __dirname = dirname(__filename);
2528

29+
const require = createRequire(import.meta.url);
30+
// const scramjetDistPath = path.join(
31+
// path.dirname(require.resolve("@mercuryworkshop/scramjet/package.json")),
32+
// "dist"
33+
// );
34+
// Resolve the exported entry file, then find the nearest "dist" folder
35+
const scramjetEntry = require.resolve("@mercuryworkshop/scramjet");
36+
let probe = dirname(scramjetEntry);
37+
const root = path.parse(probe).root;
38+
while (probe !== root && !fs.existsSync(path.join(probe, "dist", "scramjet.all.js"))) {
39+
probe = dirname(probe);
40+
}
41+
const scramjetDistPath = path.join(probe, "dist");
2642

2743
const app = express();
2844
const bareServer = createBareServer("/bare/")
2945

3046

3147
app.use(express.json());
3248

49+
wisp.options.dns_method = "resolve";
50+
wisp.options.dns_servers = ["1.1.1.3", "1.0.0.3"];
51+
wisp.options.dns_result_order = "ipv4first";
52+
wisp.options.allow_udp_streams = false;
53+
54+
logging.set_level(logging.NONE);
3355

3456
// Function to read file content
3557
function readFileContent(filePath) {
@@ -189,6 +211,35 @@ app.get('/app2/:appName', async (req, res) => {
189211
}
190212
});
191213

214+
app.get('/app3/:appName', async (req, res) => {
215+
const appName = validator.escape(req.params.appName);
216+
try {
217+
const filePath = path.join(__dirname, 'public', 'app3.html');
218+
const headPath = path.join(__dirname, 'src', 'head.html');
219+
const footerPath = path.join(__dirname, 'src', 'footer.html');
220+
const navbarPath = path.join(__dirname, 'src', 'navbar.html');
221+
222+
const [htmlContent, headContent, footerContent, navbarContent] = await Promise.all([
223+
readFileContent(filePath),
224+
readFileContent(headPath),
225+
readFileContent(footerPath),
226+
readFileContent(navbarPath)
227+
]);
228+
229+
// Replace placeholders with actual content
230+
let modifiedData = htmlContent
231+
.replace(/{{appName}}/g, appName)
232+
.replace(/{{head}}/g, headContent)
233+
.replace(/{{footer}}/g, footerContent)
234+
.replace(/{{navbar}}/g, navbarContent);
235+
236+
res.send(modifiedData);
237+
} catch (error) {
238+
console.error(`Error reading file: ${error}`);
239+
res.status(500).send('Server error');
240+
}
241+
});
242+
192243

193244
// Middleware to handle template replacements
194245
app.use(async (req, res, next) => {
@@ -258,6 +309,7 @@ app.use("/epoxy/", express.static(epoxyPath));
258309
app.use("/libcurl/", express.static(libcurlPath));
259310
app.use("/bareasmodule/", express.static(bareModulePath));
260311
app.use("/baremux/", express.static(baremuxPath));
312+
app.use("/scram/", express.static(scramjetDistPath));
261313

262314
app.use("/bare", cors({ origin: true }));
263315

0 commit comments

Comments
 (0)