0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00
ghost/core/server/web/maintenance/index.js
Naz d60e36ab57
Added "maintenance" app serving 503 page
refs #12568

- When the server is in maintenance mode (e.g. during migration) it needs to serve a 503 page. Previously this role was delegated to the "frontend" which tightly coupled server bootup and frontend.
- With a dedicated HTTP application serving up 503 server is no longer coupled to the frontend during maintenance
2021-02-02 16:11:35 +00:00

51 lines
1.6 KiB
JavaScript

const hbs = require('express-hbs');
const compress = require('compression');
const debug = require('ghost-ignition').debug('web:maintenance');
const constants = require('@tryghost/constants');
const express = require('../../../shared/express');
const config = require('../../../shared/config');
const {servePublicFile} = require('../site/middleware');
const createHbsEngine = () => {
const engine = hbs.create();
engine.registerHelper('asset', require('../../../frontend/helpers/asset'));
return engine.express4();
};
module.exports = function setupMaintenanceApp() {
debug('MaintenanceApp setup start');
const app = express('maintenance');
// enabled gzip compression by defaulti
if (config.get('compress') !== false) {
app.use(compress());
}
app.engine('hbs', createHbsEngine());
app.set('view engine', 'hbs');
app.set('views', config.get('paths').defaultViews);
// Serve stylesheets for default templates
app.use(servePublicFile('public/ghost.css', 'text/css', constants.ONE_HOUR_S));
app.use(servePublicFile('public/ghost.min.css', 'text/css', constants.ONE_YEAR_S));
// Serve images for default templates
app.use(servePublicFile('public/404-ghost@2x.png', 'image/png', constants.ONE_HOUR_S));
app.use(servePublicFile('public/404-ghost.png', 'image/png', constants.ONE_HOUR_S));
app.use('/', (req, res) => {
const data = {
message: 'Maintenance',
statusCode: 503
};
res.render('error', data, (err, html) => {
return res.send(html);
});
});
debug('MaintenanceApp setup end');
return app;
};