@@ -7,6 +7,8 @@ import cookieParser from "cookie-parser";
77import cors from "cors" ;
88import express from "express" ;
99import basicAuth from "express-basic-auth" ;
10+ import bareMuxNode from "@mercuryworkshop/bare-mux/node" ;
11+ import { server as wisp } from "@mercuryworkshop/wisp-js/server" ;
1012import mime from "mime" ;
1113import fetch from "node-fetch" ;
1214// import { setupMasqr } from "./Masqr.js";
@@ -18,10 +20,21 @@ const __dirname = process.cwd();
1820const server = http . createServer ( ) ;
1921const app = express ( ) ;
2022const 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+ ) ;
2131const PORT = process . env . PORT || 8080 ;
2232const cache = new Map ( ) ;
2333const 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+
2538if ( 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+
93117app . use ( express . static ( path . join ( __dirname , "static" ) ) ) ;
94118app . use ( "/ca" , cors ( { origin : true } ) ) ;
119+ app . use ( "/bm" , express . static ( baremuxPath , transportStaticOptions ) ) ;
120+ app . use ( "/ep" , express . static ( epoxyDistPath , transportStaticOptions ) ) ;
95121
96122const 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
0 commit comments