mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 16:42:17 +03:00
53d14fd8e3
- Added a wrapper around express.Router to our shared/express util - Also export static and _express - Use this shared util everywhre, meaning express is only used directly in this one file - ATM this file is mostly an experiment / debug helper, it might be removed again later - The aim is to have a minimal framework wrapping express that allows us to: - reduce our usage of express() in favour of Router() - unify some of our duplicated logic - fix some structural issues e.g. Sentry - make it easier to understand the codebase
37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
const debug = require('ghost-ignition').debug('shared:express');
|
|
const express = require('express');
|
|
const sentry = require('./sentry');
|
|
|
|
module.exports = (name) => {
|
|
debug('new app start', name);
|
|
const app = express();
|
|
app.set('name', name);
|
|
|
|
// Make sure 'req.secure' is valid for proxied requests
|
|
// (X-Forwarded-Proto header will be checked, if present)
|
|
app.enable('trust proxy');
|
|
|
|
// Sentry must be our first error handler. Mounting it here means all custom error handlers will come after
|
|
app.use(sentry.errorHandler);
|
|
|
|
debug('new app end', name);
|
|
return app;
|
|
};
|
|
|
|
// Wrap the main express router call
|
|
// This is mostly an experiement, and can likely be removed soon
|
|
module.exports.Router = (name, options) => {
|
|
debug('new Router start', name);
|
|
const router = express.Router(options);
|
|
|
|
router.use(sentry.errorHandler);
|
|
|
|
debug('new Router end', name);
|
|
return router;
|
|
};
|
|
|
|
module.exports.static = express.static;
|
|
|
|
// Export the OG module for testing based on the internals
|
|
module.exports._express = express;
|