From 7b273166ed1afd1263641ad77fba97a045b257e0 Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Thu, 22 Feb 2024 12:20:29 -0600 Subject: [PATCH] maybe fix it? --- index.js | 116 +++++++++++++++++++++++++++---------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/index.js b/index.js index ee7048e..3726b9b 100644 --- a/index.js +++ b/index.js @@ -19,64 +19,6 @@ const bare = createBareServer("/bare/"); console.log(chalk.gray("Starting Bare...")); console.log(chalk.gray("Starting Rammerhead...")); -const rh = createRammerhead(); - -const rammerheadScopes = [ - "/rammerhead.js", - "/hammerhead.js", - "/transport-worker.js", - "/task.js", - "/iframe-task.js", - "/worker-hammerhead.js", - "/messaging", - "/sessionexists", - "/deletesession", - "/newsession", - "/editsession", - "/needpassword", - "/syncLocalStorage", - "/api/shuffleDict" -]; - -const rammerheadSession = /^\/[a-z0-9]{32}/; - -function shouldRouteRh(req) { - const url = new URL(req.url, "http://0.0.0.0"); - return ( - rammerheadScopes.includes(url.pathname) || - rammerheadSession.test(url.pathname) - ); -} - -function routeRhRequest(req, res) { - rh.emit("request", req, res); -} - -function routeRhUpgrade(req, socket, head) { - rh.emit("upgrade", req, socket, head); -} - -let server = createServer(); -server.on("request", (req, res) => { - if (bare.shouldRoute(req)) { - bare.routeRequest(req, res); - } else if (shouldRouteRh(req)) { - routeRhRequest(req, res); - } else { - app(req, res); - } -}); - -server.on("upgrade", (req, socket, head) => { - if (bare.shouldRoute(req)) { - bare.routeUpgrade(req, socket, head); - } else if (shouldRouteRh(req)) { - routeRhUpgrade(req, socket, head); - } else { - socket.end(); - } -}); - const app = express(); app.use(compression()); app.use(express.static(path.join(process.cwd(), "static"))); @@ -106,6 +48,64 @@ app.get("*", function (req, res) { res.redirect(302, "/404.html"); }); +const rh = createRammerhead(); + +const rammerheadScopes = [ + "/rammerhead.js", + "/hammerhead.js", + "/transport-worker.js", + "/task.js", + "/iframe-task.js", + "/worker-hammerhead.js", + "/messaging", + "/sessionexists", + "/deletesession", + "/newsession", + "/editsession", + "/needpassword", + "/syncLocalStorage", + "/api/shuffleDict" +]; +const rammerheadSession = /^\/[a-z0-9]{32}/; + +let server = createServer(); +server.on("request", (req, res) => { + if (bare.shouldRoute(req)) { + bare.routeRequest(req, res); + } else if (shouldRouteRh(req)) { + routeRhRequest(req, res); + } else { + app(req, res); + } +}); + +server.on("upgrade", (req, socket, head) => { + if (bare.shouldRoute(req)) { + bare.routeUpgrade(req, socket, head); + } else if (shouldRouteRh(req)) { + routeRhUpgrade(req, socket, head); + } else { + socket.end(); + } +}); + + +function shouldRouteRh(req) { + const url = new URL(req.url, "http://0.0.0.0"); + return ( + rammerheadScopes.includes(url.pathname) || + rammerheadSession.test(url.pathname) + ); +} + +function routeRhRequest(req, res) { + rh.emit("request", req, res); +} + +function routeRhUpgrade(req, socket, head) { + rh.emit("upgrade", req, socket, head); +} + console.log(chalk.gray("Starting Alu...")); console.log(chalk.green("Alu started successfully!")); server.on("listening", () => {