Fixed express app stacking

refs https://github.com/TryGhost/Toolbox/issues/152

- Because the root app module was initialized only once per runtime it caused all the express apps to stack on each other causing all sorts of strange behavior when trying to test redirects/vhost mounts etc. Lesson here: be very cautious of how the module is initialized, an explicit function is almost always a better way!
This commit is contained in:
Naz 2021-12-03 20:26:51 +04:00 committed by naz
parent 91338b23d9
commit abcd715907
2 changed files with 9 additions and 5 deletions

View File

@ -27,10 +27,14 @@ const maintenanceMiddleware = (req, res, next) => {
fs.createReadStream(path.resolve(__dirname, './server/views/maintenance.html')).pipe(res);
};
const rootApp = express('root');
rootApp.use(sentry.requestHandler);
const rootApp = () => {
const app = express('root');
app.use(sentry.requestHandler);
rootApp.enable('maintenance');
rootApp.use(maintenanceMiddleware);
app.enable('maintenance');
app.use(maintenanceMiddleware);
return app;
};
module.exports = rootApp;

View File

@ -371,7 +371,7 @@ async function bootGhost({backend = true, frontend = true, server = true} = {})
// Step 2 - Start server with minimal app in global maintenance mode
debug('Begin: load server + minimal app');
const rootApp = require('./app');
const rootApp = require('./app')();
if (server) {
const GhostServer = require('./server/ghost-server');