diff --git a/core/server/services/members/middleware.js b/core/server/services/members/middleware.js index 78bb770650..670bed042a 100644 --- a/core/server/services/members/middleware.js +++ b/core/server/services/members/middleware.js @@ -1,6 +1,4 @@ const common = require('../../lib/common'); -const constants = require('../../lib/constants'); -const shared = require('../../web/shared'); const labsService = require('../labs'); const membersService = require('./index'); @@ -62,6 +60,9 @@ const exchangeTokenForSession = async function (req, res, next) { }; const decorateResponse = function (req, res, next) { + if (!labsService.isSet('members')) { + return next(); + } res.locals.member = req.member; next(); }; @@ -69,37 +70,12 @@ const decorateResponse = function (req, res, next) { // @TODO only loads this stuff if members is enabled // Set req.member & res.locals.member if a cookie is set module.exports = { - public: [ - shared.middlewares.labs.members, - shared.middlewares.servePublicFile.createPublicFileMiddleware( - 'public/members.js', - 'application/javascript', - constants.ONE_YEAR_S - ) - ], - publicMinified: [ - shared.middlewares.labs.members, - shared.middlewares.servePublicFile.createPublicFileMiddleware( - 'public/members.min.js', - 'application/javascript', - constants.ONE_YEAR_S - ) - ], createSessionFromToken: [ getMemberDataFromSession, exchangeTokenForSession, decorateResponse ], - getIdentityToken: [ - shared.middlewares.labs.members, - getIdentityToken - ], - deleteSession: [ - shared.middlewares.labs.members, - deleteSession - ], - stripeWebhooks: [ - shared.middlewares.labs.members, - (req, res, next) => membersService.api.middleware.handleStripeWebhook(req, res, next) - ] + getIdentityToken, + deleteSession, + stripeWebhooks: (req, res, next) => membersService.api.middleware.handleStripeWebhook(req, res, next) }; diff --git a/core/server/web/site/app.js b/core/server/web/site/app.js index 3685af7bae..7f80badfd6 100644 --- a/core/server/web/site/app.js +++ b/core/server/web/site/app.js @@ -109,9 +109,12 @@ module.exports = function setupSiteApp(options = {}) { siteApp.use(mw.serveFavicon()); // /public/members.js - siteApp.get('/public/members.js', membersMiddleware.public); + siteApp.get('/public/members.js', shared.middlewares.labs.members, + shared.middlewares.servePublicFile('public/members.js', 'application/javascript', constants.ONE_YEAR_S)); + // /public/members.min.js - siteApp.get('/public/members.min.js', membersMiddleware.publicMinified); + siteApp.get('/public/members.min.js', shared.middlewares.labs.members, + shared.middlewares.servePublicFile('public/members.min.js', 'application/javascript', constants.ONE_YEAR_S)); // Serve sitemap.xsl file siteApp.use(shared.middlewares.servePublicFile('sitemap.xsl', 'text/xsl', constants.ONE_DAY_S)); @@ -136,10 +139,11 @@ module.exports = function setupSiteApp(options = {}) { // Members middleware // Initializes members specific routes as well as assigns members specific data to the req/res objects - siteApp.get('/members/ssr', membersMiddleware.getIdentityToken); - siteApp.delete('/members/ssr', membersMiddleware.deleteSession); - siteApp.post('/members/webhooks/stripe', membersMiddleware.stripeWebhooks); + siteApp.get('/members/ssr', shared.middlewares.labs.members, membersMiddleware.getIdentityToken); + siteApp.delete('/members/ssr', shared.middlewares.labs.members, membersMiddleware.deleteSession); + siteApp.post('/members/webhooks/stripe', shared.middlewares.labs.members, membersMiddleware.stripeWebhooks); + // Currently global handling for signing in with ?token= siteApp.use(membersMiddleware.createSessionFromToken); // Theme middleware