From 41db9436e835ef6d70c429d63070b252273db330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 1 Dec 2021 17:18:38 -0500 Subject: [PATCH] perf: only add middleware if relativePath is set --- src/middleware/index.js | 13 ------------- src/webserver.js | 10 ++++++++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/middleware/index.js b/src/middleware/index.js index d42ef87436..ea22f285af 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -59,19 +59,6 @@ middleware.ensureLoggedIn = (req, res, next) => { setImmediate(next); }; -middleware.ensureRelativePath = (req, res, next) => { - const prefix = nconf.get('relative_path'); - if (!prefix) { - return setImmediate(next); - } - - if (!req.path.startsWith(prefix)) { - return controllers.helpers.redirect(res, req.path); - } - - return next(); -}; - Object.assign(middleware, { admin: require('./admin'), ...require('./header'), diff --git a/src/webserver.js b/src/webserver.js index 9dae76d496..c5f4aefa86 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -137,8 +137,14 @@ function setupExpressApp(app) { const compression = require('compression'); app.use(compression()); } - - app.use(middleware.ensureRelativePath); + if (relativePath) { + app.use((req, res, next) => { + if (!req.path.startsWith(relativePath)) { + return require('./controllers/helpers').redirect(res, req.path); + } + next(); + }); + } app.get(`${relativePath}/ping`, pingController.ping); app.get(`${relativePath}/sping`, pingController.ping);