@@ -7,7 +7,8 @@ import { bareModulePath } from "@mercuryworkshop/bare-as-module3";
77import { baremuxPath } from "@mercuryworkshop/bare-mux/node" ;
88//import { join } from "node:path";
99import { 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
1213import { createBareServer } from "@tomphttp/bare-server-node" ;
1314import cors from "cors" ;
@@ -19,17 +20,38 @@ import { fileURLToPath } from 'url';
1920
2021import validator from 'validator' ;
2122
23+ import { createRequire } from "node:module" ;
24+
2225
2326const __filename = fileURLToPath ( import . meta. url ) ;
2427const __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
2743const app = express ( ) ;
2844const bareServer = createBareServer ( "/bare/" )
2945
3046
3147app . 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
3557function 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
194245app . use ( async ( req , res , next ) => {
@@ -258,6 +309,7 @@ app.use("/epoxy/", express.static(epoxyPath));
258309app . use ( "/libcurl/" , express . static ( libcurlPath ) ) ;
259310app . use ( "/bareasmodule/" , express . static ( bareModulePath ) ) ;
260311app . use ( "/baremux/" , express . static ( baremuxPath ) ) ;
312+ app . use ( "/scram/" , express . static ( scramjetDistPath ) ) ;
261313
262314app . use ( "/bare" , cors ( { origin : true } ) ) ;
263315
0 commit comments