From d722f3b8b6df62338a064f1b1eca546f8335e366 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 19 Feb 2019 15:49:34 -0500 Subject: [PATCH] fix: mounting of all-route middlewares to router instead of app related to julianlam/nodebb-plugin-session-sharing#73 These three lines haven't changed in two years, but it makes more sense for them to be called against the relative path router, otherwise req.originalUrl contains the relative path, which is not necessary. --- src/routes/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/routes/index.js b/src/routes/index.js index 2a6d787f78..b6809d1e54 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -95,12 +95,11 @@ module.exports = function (app, middleware, callback) { router.render = function () { app.render.apply(app, arguments); }; - var relativePath = nconf.get('relative_path'); var ensureLoggedIn = require('connect-ensure-login'); - app.all(relativePath + '(/+api|/+api/*?)', middleware.prepareAPI); - app.all(relativePath + '(/+api/admin|/+api/admin/*?)', middleware.isAdmin); - app.all(relativePath + '(/+admin|/+admin/*?)', ensureLoggedIn.ensureLoggedIn(nconf.get('relative_path') + '/login?local=1'), middleware.applyCSRF, middleware.isAdmin); + router.all('(/+api|/+api/*?)', middleware.prepareAPI); + router.all('(/+api/admin|/+api/admin/*?)', middleware.isAdmin); + router.all('(/+admin|/+admin/*?)', ensureLoggedIn.ensureLoggedIn(nconf.get('relative_path') + '/login?local=1'), middleware.applyCSRF, middleware.isAdmin); app.use(middleware.stripLeadingSlashes);