Wired up middleware to handle unsubscribing

no-issue
This commit is contained in:
Fabien O'Carroll 2019-11-05 17:03:15 +07:00
parent 73b00e77c2
commit a7e7f74f8b

View File

@ -15,6 +15,7 @@ const labsService = require('../../services/labs');
const urlUtils = require('../../lib/url-utils');
const sitemapHandler = require('../../../frontend/services/sitemap/handler');
const themeMiddleware = require('../../../frontend/services/themes').middleware;
const megaService = require('../../services/mega');
const membersService = require('../../services/members');
const siteRoutes = require('./routes');
const shared = require('../shared');
@ -189,6 +190,21 @@ module.exports = function setupSiteApp(options = {}) {
return next();
}
});
siteApp.use(async function (req, res, next) {
if (!labsService.isSet('members')) {
return next();
}
if (!req.url.includes('unsubscribe=')) {
return next();
}
try {
await megaService.mega.handleUnsubscribeRequest(req);
next();
} catch (err) {
common.logging.warn(err.message);
return next();
}
});
siteApp.use(function (req, res, next) {
res.locals.member = req.member;
next();