0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Moved maintenance app to separate package

refs #12568

- Made a package out of maintenance app to keep as little code in the repository
This commit is contained in:
Naz 2021-01-28 19:14:58 +13:00 committed by Daniel Lockyer
parent dcb89f2be0
commit 9bff415572
No known key found for this signature in database
GPG key ID: FFBC6FA2A6F6ABC1
4 changed files with 10 additions and 55 deletions

View file

@ -1,10 +1,10 @@
const hbs = require('express-hbs');
const MaintenanceApp = require('@tryghost/maintenance');
const {i18n} = require('../../lib/common');
const logging = require('../../../shared/logging');
const express = require('../../../shared/express');
const config = require('../../../shared/config');
const {servePublicFile, serveFavicon} = require('../site/middleware');
const MaintenanceApp = require('./maintenance-app');
const createHbsEngine = () => {
const engine = hbs.create();

View file

@ -1,53 +0,0 @@
const compression = require('compression');
const errors = require('@tryghost/errors');
const constants = require('@tryghost/constants');
const debug = require('ghost-ignition').debug('maintenance:app');
class MaintenanceApp {
constructor({logging, i18n, express, viewEngine, compress, views, servePublicFile, serveFavicon}) {
debug('MaintenanceApp setup start');
const app = express('maintenance');
if (compress !== false) {
app.use(compression());
}
app.engine('hbs', viewEngine);
app.set('view engine', 'hbs');
app.set('views', views);
// Serve favicon.ico and favicon.png
app.use(serveFavicon());
// 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 error = new errors.MaintenanceError({
message: i18n.t('errors.general.maintenance')
});
logging.error({req: req, res: res, err: error});
res.render('error', error, (err, html) => {
// never cache errors
res.set({
'Cache-Control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
});
res.status(error.statusCode);
return res.send(html);
});
});
debug('MaintenanceApp setup end');
this.app = app;
}
}
module.exports = MaintenanceApp;

View file

@ -56,6 +56,7 @@
"@tryghost/kg-markdown-html-renderer": "3.0.0",
"@tryghost/kg-mobiledoc-html-renderer": "3.0.1",
"@tryghost/magic-link": "0.6.4",
"@tryghost/maintenance": "0.1.0",
"@tryghost/members-api": "0.37.7",
"@tryghost/members-csv": "0.4.2",
"@tryghost/members-ssr": "0.8.8",

View file

@ -546,6 +546,13 @@
jsonwebtoken "^8.5.1"
lodash "^4.17.15"
"@tryghost/maintenance@0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@tryghost/maintenance/-/maintenance-0.1.0.tgz#cb2c4dff2c1292ca7a07b88f3a658832e33b3259"
integrity sha512-f91Wngx4UbzGuSlCN6TI9EAvS1nofIYY653+3OO3fx/2A9ehbzMRWraUH3GY05xKRc8CnW+msGkRrPgiMIa/Kw==
dependencies:
ghost-ignition "^4.4.3"
"@tryghost/members-api@0.37.7":
version "0.37.7"
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.37.7.tgz#95102f775a0647898cf26919eb543a5bd0aa7778"
@ -4116,7 +4123,7 @@ ghost-ignition@4.4.2:
prettyjson "1.2.1"
uuid "8.3.2"
ghost-ignition@4.4.3:
ghost-ignition@4.4.3, ghost-ignition@^4.4.3:
version "4.4.3"
resolved "https://registry.yarnpkg.com/ghost-ignition/-/ghost-ignition-4.4.3.tgz#c837ab11e1f3a1cfd22cc24df6b506a9afc1bc25"
integrity sha512-eViE/ae+AGV/YmVbTq2W5TBWVu724EUJ0pjtSwa4q6o1+fXxMIqoELJaxMX+Gc9PBK0nI3J+E0JI8GdrEiqndg==