mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
This reverts commit 9a0d143fb1
- main is now a precursor of 5.0 which should have email notification turned on
- had to add missing `err` in the errorHandler middleware as it was not triggering the versionMissmatchHandler otherwise
40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
const APIVersionCompatibilityService = require('@tryghost/api-version-compatibility-service');
|
|
const VersionNotificationsDataService = require('@tryghost/version-notifications-data-service');
|
|
const versionMismatchHandler = require('@tryghost/mw-api-version-mismatch');
|
|
const ghostVersion = require('@tryghost/version');
|
|
const {GhostMailer} = require('../mail');
|
|
const settingsService = require('../../services/settings');
|
|
const models = require('../../models');
|
|
|
|
let serviceInstance;
|
|
|
|
const init = () => {
|
|
const ghostMailer = new GhostMailer();
|
|
const versionNotificationsDataService = new VersionNotificationsDataService({
|
|
UserModel: models.User,
|
|
settingsService: settingsService.getSettingsBREADServiceInstance()
|
|
});
|
|
|
|
serviceInstance = new APIVersionCompatibilityService({
|
|
sendEmail: (options) => {
|
|
// NOTE: not using bind here because mockMailer is having trouble mocking bound methods
|
|
return ghostMailer.send(options);
|
|
},
|
|
fetchEmailsToNotify: versionNotificationsDataService.getNotificationEmails.bind(versionNotificationsDataService),
|
|
fetchHandled: versionNotificationsDataService.fetchNotification.bind(versionNotificationsDataService),
|
|
saveHandled: versionNotificationsDataService.saveNotification.bind(versionNotificationsDataService)
|
|
});
|
|
};
|
|
|
|
module.exports.errorHandler = (err, req, res, next) => {
|
|
return versionMismatchHandler(serviceInstance)(err, req, res, next);
|
|
};
|
|
|
|
module.exports.contentVersion = (req, res, next) => {
|
|
if (req.header('accept-version')) {
|
|
res.header('Content-Version', `v${ghostVersion.safe}`);
|
|
}
|
|
next();
|
|
};
|
|
|
|
module.exports.init = init;
|