2021-10-05 14:17:18 +03:00
|
|
|
const DynamicRedirectManager = require('@tryghost/express-dynamic-redirects');
|
|
|
|
const OffersModule = require('@tryghost/members-offers');
|
|
|
|
|
|
|
|
const stripeService = require('../stripe');
|
|
|
|
|
|
|
|
const config = require('../../../shared/config');
|
|
|
|
const urlUtils = require('../../../shared/url-utils');
|
|
|
|
const models = require('../../models');
|
|
|
|
|
|
|
|
const redirectManager = new DynamicRedirectManager({
|
2021-10-13 11:04:49 +03:00
|
|
|
permanentMaxAge: config.get('caching:customRedirects:maxAge'),
|
|
|
|
getSubdirectoryURL: (pathname) => {
|
|
|
|
return urlUtils.urlJoin(urlUtils.getSubdir(), pathname);
|
|
|
|
}
|
|
|
|
});
|
2021-10-05 14:17:18 +03:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
async init() {
|
|
|
|
const offersModule = OffersModule.create({
|
|
|
|
OfferModel: models.Offer,
|
2021-10-15 12:07:07 +03:00
|
|
|
OfferRedemptionModel: models.OfferRedemption,
|
2021-10-05 14:17:18 +03:00
|
|
|
redirectManager: redirectManager,
|
|
|
|
stripeAPIService: stripeService.api
|
|
|
|
});
|
|
|
|
|
|
|
|
this.api = offersModule.api;
|
2021-11-03 18:17:33 +03:00
|
|
|
|
|
|
|
await offersModule.init();
|
2021-10-05 14:17:18 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
api: null,
|
|
|
|
|
|
|
|
middleware: redirectManager.handleRequest
|
|
|
|
};
|