From 2b4534f403c9e3a7a2802f39394ff661326667c1 Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Thu, 22 Feb 2024 12:25:48 -0600 Subject: [PATCH] small refactor of index.js --- index.js | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index 3726b9b..89b0987 100644 --- a/index.js +++ b/index.js @@ -14,13 +14,31 @@ dotenv.config(); if (!existsSync("./dist")) build(); const PORT = process.env.PORT || 3000; - +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}/; const bare = createBareServer("/bare/"); console.log(chalk.gray("Starting Bare...")); -console.log(chalk.gray("Starting Rammerhead...")); const app = express(); -app.use(compression()); +app.use(compression({ threshold: 0, filter: () => true }) +); app.use(express.static(path.join(process.cwd(), "static"))); app.use(express.static(path.join(process.cwd(), "build"))); app.use("/uv/", express.static(uvPath)); @@ -48,26 +66,6 @@ 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)) { @@ -89,7 +87,6 @@ server.on("upgrade", (req, socket, head) => { } }); - function shouldRouteRh(req) { const url = new URL(req.url, "http://0.0.0.0"); return ( @@ -106,6 +103,7 @@ 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", () => {