perf: only add middleware if relativePath is set

This commit is contained in:
Barış Soner Uşaklı
2021-12-01 17:18:38 -05:00
parent a3bdb70617
commit 41db9436e8
2 changed files with 8 additions and 15 deletions

View File

@@ -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);