mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46: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);
|
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, {
|
Object.assign(middleware, {
|
||||||
admin: require('./admin'),
|
admin: require('./admin'),
|
||||||
...require('./header'),
|
...require('./header'),
|
||||||
|
|||||||
@@ -137,8 +137,14 @@ function setupExpressApp(app) {
|
|||||||
const compression = require('compression');
|
const compression = require('compression');
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
}
|
}
|
||||||
|
if (relativePath) {
|
||||||
app.use(middleware.ensureRelativePath);
|
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}/ping`, pingController.ping);
|
||||||
app.get(`${relativePath}/sping`, pingController.ping);
|
app.get(`${relativePath}/sping`, pingController.ping);
|
||||||
|
|||||||
Reference in New Issue
Block a user