mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
perf: only add middleware if relativePath is set
This commit is contained in:
@@ -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'),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user