From cbca560f9248d2b1c798c3d014177372bff6b37e Mon Sep 17 00:00:00 2001 From: mikiher Date: Tue, 15 Oct 2024 06:40:14 +0300 Subject: [PATCH] server.js: add base path to all non-base-path requests --- server/Server.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/Server.js b/server/Server.js index 7e541e61..d8265237 100644 --- a/server/Server.js +++ b/server/Server.js @@ -243,6 +243,15 @@ class Server { await this.auth.initPassportJs() const router = express.Router() + // if RouterBasePath is set, modify all requests to include the base path + if (global.RouterBasePath) { + app.use((req, res, next) => { + if (!req.url.startsWith(global.RouterBasePath)) { + req.url = `${global.RouterBasePath}${req.url}` + } + next() + }) + } app.use(global.RouterBasePath, router) app.disable('x-powered-by') @@ -340,7 +349,7 @@ class Server { Logger.info('Received ping') res.json({ success: true }) }) - app.get('/healthcheck', (req, res) => res.sendStatus(200)) + router.get('/healthcheck', (req, res) => res.sendStatus(200)) this.server.listen(this.Port, this.Host, () => { if (this.Host) Logger.info(`Listening on http://${this.Host}:${this.Port}`)