0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Unhooked shared mw from members service

This commit is contained in:
Hannah Wolfe 2020-04-21 16:48:42 +01:00
parent 406218489c
commit 0897b0ef3c
2 changed files with 15 additions and 35 deletions

View file

@ -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)
};

View file

@ -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