diff --git a/ghost/core/core/app.js b/ghost/core/core/app.js index 76bde97d04..5a996f6d34 100644 --- a/ghost/core/core/app.js +++ b/ghost/core/core/app.js @@ -15,7 +15,7 @@ const isMaintenanceModeEnabled = (req) => { }; // We never want middleware functions to be anonymous -const maintenanceMiddleware = (req, res, next) => { +const maintenanceMiddleware = function maintenanceMiddleware(req, res, next) { if (!isMaintenanceModeEnabled(req)) { return next(); } diff --git a/ghost/core/core/frontend/web/middleware/error-handler.js b/ghost/core/core/frontend/web/middleware/error-handler.js index 9caec2ce20..b1c849414a 100644 --- a/ghost/core/core/frontend/web/middleware/error-handler.js +++ b/ghost/core/core/frontend/web/middleware/error-handler.js @@ -34,7 +34,7 @@ const errorFallbackMessage = err => `

${tpl(messages.oopsErrorTemplateHasErro

${tpl(messages.whilstTryingToRender)}

${err.statusCode}
${escapeExpression(err.message || err)}
`; -const themeErrorRenderer = (err, req, res, next) => { +const themeErrorRenderer = function themeErrorRenderer(err, req, res, next) { // If the error code is explicitly set to STATIC_FILE_NOT_FOUND, // Skip trying to render an HTML error, and move on to the basic error renderer // We do this because customised 404 templates could reference the image that's missing diff --git a/ghost/core/core/frontend/web/site.js b/ghost/core/core/frontend/web/site.js index 554e5f7bf4..8a8fea58d1 100644 --- a/ghost/core/core/frontend/web/site.js +++ b/ghost/core/core/frontend/web/site.js @@ -50,7 +50,7 @@ module.exports = function setupSiteApp(routerConfig) { // enable CORS headers (allows admin client to hit front-end when configured on separate URLs) siteApp.use(mw.cors); - siteApp.use(async (req, res, next) => { + siteApp.use(async function nestApp(req, res, next) { if (labs.isSet('NestPlayground') || labs.isSet('ActivityPub')) { const originalExpressApp = req.app; const app = await GhostNestApp.getApp(); @@ -112,7 +112,9 @@ module.exports = function setupSiteApp(routerConfig) { siteApp.use( '/members/.well-known', shared.middleware.cacheControl('public', {maxAge: config.get('caching:wellKnown:maxAge')}), - (req, res, next) => membersService.api.middleware.wellKnown(req, res, next) + function lazyWellKnownMw(req, res, next) { + return membersService.api.middleware.wellKnown(req, res, next); + } ); // Recommendations well-known diff --git a/ghost/core/core/server/api/endpoints/session.js b/ghost/core/core/server/api/endpoints/session.js index 9359339d19..20d65f86a6 100644 --- a/ghost/core/core/server/api/endpoints/session.js +++ b/ghost/core/core/server/api/endpoints/session.js @@ -31,7 +31,7 @@ const session = { email: object.username, password: object.password }).then((user) => { - return Promise.resolve((req, res, next) => { + return Promise.resolve(function sessionMiddleware(req, res, next) { req.brute.reset(function (err) { if (err) { return next(err); @@ -60,7 +60,7 @@ const session = { }); }, delete() { - return Promise.resolve((req, res, next) => { + return Promise.resolve(function destroySessionMw(req, res, next) { auth.session.destroySession(req, res, next); }); } diff --git a/ghost/core/core/server/web/admin/app.js b/ghost/core/core/server/web/admin/app.js index b111f41903..d67dc2b7b5 100644 --- a/ghost/core/core/server/web/admin/app.js +++ b/ghost/core/core/server/web/admin/app.js @@ -34,7 +34,7 @@ module.exports = function setupAdminApp() { // request to the Admin API /users/me/ endpoint to check if the user is logged in. // // Used by comments-ui to add moderation options to front-end comments when logged in. - adminApp.use('/auth-frame', (req, res, next) => { + adminApp.use('/auth-frame', function authFrameMw(req, res, next) { // only render content when we have an Admin session cookie, // otherwise return a 204 to avoid JS and API requests being made unnecessarily try { diff --git a/ghost/core/core/server/web/api/endpoints/admin/app.js b/ghost/core/core/server/web/api/endpoints/admin/app.js index b458efc94f..f315febc38 100644 --- a/ghost/core/core/server/web/api/endpoints/admin/app.js +++ b/ghost/core/core/server/web/api/endpoints/admin/app.js @@ -35,7 +35,7 @@ module.exports = function setupApiApp() { // Routing apiApp.use(routes()); - apiApp.use(async (req, res, next) => { + apiApp.use(async function nestApp(req, res, next) { if (labs.isSet('NestPlayground') || labs.isSet('ActivityPub')) { const originalExpressApp = req.app; const app = await GhostNestApp.getApp(); diff --git a/ghost/core/core/server/web/members/app.js b/ghost/core/core/server/web/members/app.js index 52bb8ac18e..df8daaa79d 100644 --- a/ghost/core/core/server/web/members/app.js +++ b/ghost/core/core/server/web/members/app.js @@ -61,11 +61,19 @@ module.exports = function setupMembersApp() { shared.middleware.brute.membersAuthEnumeration, // Prevent brute forcing passwords for the same email address shared.middleware.brute.membersAuth, - (req, res, next) => membersService.api.middleware.sendMagicLink(req, res, next) + function lazySendMagicLinkMw(req, res, next) { + return membersService.api.middleware.sendMagicLink(req, res, next); + } ); - membersApp.post('/api/create-stripe-checkout-session', (req, res, next) => membersService.api.middleware.createCheckoutSession(req, res, next)); - membersApp.post('/api/create-stripe-update-session', (req, res, next) => membersService.api.middleware.createCheckoutSetupSession(req, res, next)); - membersApp.put('/api/subscriptions/:id', (req, res, next) => membersService.api.middleware.updateSubscription(req, res, next)); + membersApp.post('/api/create-stripe-checkout-session', function lazyCreateCheckoutSessionMw(req, res, next) { + return membersService.api.middleware.createCheckoutSession(req, res, next); + }); + membersApp.post('/api/create-stripe-update-session', function lazyCreateCheckoutSetupSessionMw(req, res, next) { + return membersService.api.middleware.createCheckoutSetupSession(req, res, next); + }); + membersApp.put('/api/subscriptions/:id', function lazyUpdateSubscriptionMw(req, res, next) { + return membersService.api.middleware.updateSubscription(req, res, next); + }); // Comments membersApp.use('/api/comments', commentRouter()); diff --git a/ghost/core/core/server/web/parent/middleware/queue-request.js b/ghost/core/core/server/web/parent/middleware/queue-request.js index 908d0e9939..c1cd4a5fe0 100644 --- a/ghost/core/core/server/web/parent/middleware/queue-request.js +++ b/ghost/core/core/server/web/parent/middleware/queue-request.js @@ -44,7 +44,7 @@ module.exports = function queueRequest( debug(`Request completed: ${job.data.req.path}`); }); - return (req, res, next) => { + return function queueRequestMw(req, res, next) { req.queueDepth = queue.queue.getLength(); // Do not queue requests for static assets - We assume that any path diff --git a/ghost/core/core/shared/labs.js b/ghost/core/core/shared/labs.js index 2e6bccb84a..41f4dfede6 100644 --- a/ghost/core/core/shared/labs.js +++ b/ghost/core/core/shared/labs.js @@ -142,7 +142,7 @@ module.exports.enabledHelper = function enabledHelper(options, callback) { return errString; }; -module.exports.enabledMiddleware = flag => (req, res, next) => { +module.exports.enabledMiddleware = flag => function labsEnabledMw(req, res, next) { if (module.exports.isSet(flag) === true) { return next(); } else { diff --git a/ghost/members-api/lib/members-api.js b/ghost/members-api/lib/members-api.js index 808c0f4263..5b4b328789 100644 --- a/ghost/members-api/lib/members-api.js +++ b/ghost/members-api/lib/members-api.js @@ -317,7 +317,7 @@ module.exports = function MembersAPI({ return getMemberIdentityData(email); } - const forwardError = fn => async (req, res, next) => { + const forwardError = fn => async function forwardErrorMw(req, res, next) { try { await fn(req, res, next); } catch (err) { diff --git a/ghost/mw-api-version-mismatch/lib/mw-api-version-mismatch.js b/ghost/mw-api-version-mismatch/lib/mw-api-version-mismatch.js index ef3afbaeb3..93b002a98b 100644 --- a/ghost/mw-api-version-mismatch/lib/mw-api-version-mismatch.js +++ b/ghost/mw-api-version-mismatch/lib/mw-api-version-mismatch.js @@ -7,7 +7,7 @@ const versionMismatchHandler = (APIVersionCompatibilityService) => { * @param {import('express').Response} res * @param {import('express').NextFunction} next */ - return async (err, req, res, next) => { + return async function versionMismatchHandlerMiddlware(err, req, res, next) { if (err && err.errorType === 'RequestNotAcceptableError') { if (err.code === 'UPDATE_CLIENT') { const {key, type} = extractApiKey(req); diff --git a/ghost/mw-session-from-token/README.md b/ghost/mw-session-from-token/README.md index c549d5da94..b8894b58ab 100644 --- a/ghost/mw-session-from-token/README.md +++ b/ghost/mw-session-from-token/README.md @@ -23,9 +23,9 @@ const sessionFromTokenMiddleware = require('@tryghost/mw-session-from-token')({ } }); -someExpressApp.get('/some/sso/url', someSessionMiddleware, sessionFromTokenMiddleware, (req, res, next) => { +someExpressApp.get('/some/sso/url', someSessionMiddleware, sessionFromTokenMiddleware, function sessionFromTokenMiddleware(req, res, next) { res.redirect('/loggedin'); -}, (err, res, res, next) => { +}, function nextMw(err, res, res, next) => { res.redirect('/error'); }); ``` diff --git a/ghost/session-service/README.md b/ghost/session-service/README.md index 39dd3e6534..d7bb632221 100644 --- a/ghost/session-service/README.md +++ b/ghost/session-service/README.md @@ -24,7 +24,7 @@ const sessionService = SessionService({ } }); -app.use(async (req, res, next) => { +app.use(async function sessionMiddleware(req, res, next) { try { const user = await sessionService.getUserForSession(req, res); req.user = user;