mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
00c324fa4e
- Represents that logging is shared across all parts of Ghost at present
* moved core/server/lib/common/logging to core/shared/logging
* updated logging path for generic imports
* updated migration and schema imports of logging
* updated tests and index logging import
* 🔥 removed logging from common module
* fixed tests
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
const {URL} = require('url');
|
|
const mailgun = require('mailgun-js');
|
|
const logging = require('../../../shared/logging');
|
|
const configService = require('../../../shared/config');
|
|
const settingsCache = require('../settings/cache');
|
|
|
|
function createMailgun(config) {
|
|
const baseUrl = new URL(config.baseUrl);
|
|
|
|
return mailgun({
|
|
apiKey: config.apiKey,
|
|
domain: config.domain,
|
|
protocol: baseUrl.protocol,
|
|
host: baseUrl.host,
|
|
port: baseUrl.port,
|
|
endpoint: baseUrl.pathname,
|
|
retry: 5
|
|
});
|
|
}
|
|
|
|
function getInstance() {
|
|
const bulkEmailConfig = configService.get('bulkEmail');
|
|
const bulkEmailSetting = settingsCache.get('bulk_email_settings');
|
|
const hasMailgunConfig = !!(bulkEmailConfig && bulkEmailConfig.mailgun);
|
|
const hasMailgunSetting = !!(bulkEmailSetting && bulkEmailSetting.apiKey && bulkEmailSetting.baseUrl && bulkEmailSetting.domain);
|
|
if (!hasMailgunConfig && !hasMailgunSetting) {
|
|
logging.warn(`Bulk email service is not configured`);
|
|
} else {
|
|
try {
|
|
let mailgunConfig = hasMailgunConfig ? bulkEmailConfig.mailgun : bulkEmailSetting;
|
|
return createMailgun(mailgunConfig);
|
|
} catch (err) {
|
|
logging.warn(`Bulk email service is not configured`);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
module.exports = {
|
|
getInstance: getInstance
|
|
};
|