From 86ee3fedd82b72e1fddf042a43c916ae482f53a6 Mon Sep 17 00:00:00 2001 From: "kam (from the studio)" Date: Tue, 17 Jan 2023 13:51:33 +0100 Subject: [PATCH] prefix middleware --- server.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 06c9ce6..e8673f5 100644 --- a/server.js +++ b/server.js @@ -5,16 +5,22 @@ dotenv.config(); const express = require("express"); const PORT = process.env.PORT || 3000; -const index = "index.html"; +const PREFIX = process.env.PREFIX || ""; -const server = express() - .use(express.static("public")) - .get("/", (req, res) => { +const router = express.Router(); +const routes = (app) => { + app.get("/", (req, res) => { res.sendFile("index.html", { root: __dirname }); - }) - .get("/destination", (req, res) => { + }); + app.get("/destination", (req, res) => { res.sendFile("destination.html", { root: __dirname }); - }) + }); + return app; +}; + +const server = express() + .use(PREFIX, routes(router, {})) + .use(express.static("public")) .listen(PORT, () => console.log(`Listening on ${PORT}`)); const wss = new WebSocketServer({ server, clientTracking: true });