Ghost/core/server/services/offers/service.js

35 lines
1003 B
JavaScript
Raw Normal View History

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({
permanentMaxAge: config.get('caching:customRedirects:maxAge'),
getSubdirectoryURL: (pathname) => {
return urlUtils.urlJoin(urlUtils.getSubdir(), pathname);
}
});
module.exports = {
async init() {
const offersModule = OffersModule.create({
OfferModel: models.Offer,
OfferRedemptionModel: models.OfferRedemption,
redirectManager: redirectManager,
stripeAPIService: stripeService.api
});
this.api = offersModule.api;
await offersModule.init();
},
api: null,
middleware: redirectManager.handleRequest
};