add mailer
This commit is contained in:
parent
52a6627e84
commit
648c136fcf
32
lib/apis.js
32
lib/apis.js
|
@ -11,6 +11,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
// TODO xconfx.apispath
|
// TODO xconfx.apispath
|
||||||
xconfx.restPath = path.join(__dirname, '..', '..', 'packages', 'rest');
|
xconfx.restPath = path.join(__dirname, '..', '..', 'packages', 'rest');
|
||||||
xconfx.appApiGrantsPath = path.join(__dirname, '..', '..', 'packages', 'client-api-grants');
|
xconfx.appApiGrantsPath = path.join(__dirname, '..', '..', 'packages', 'client-api-grants');
|
||||||
|
xconfx.appConfigPath = path.join(__dirname, '..', '..', 'var');
|
||||||
|
|
||||||
function notConfigured(req, res) {
|
function notConfigured(req, res) {
|
||||||
var msg = "api package '" + req.pkgId + "' not configured for client uri '" + req.experienceId + "'"
|
var msg = "api package '" + req.pkgId + "' not configured for client uri '" + req.experienceId + "'"
|
||||||
|
@ -54,6 +55,12 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSiteConfig(clientUrih) {
|
||||||
|
return fs.readFileAsync(path.join(xconfx.appConfigPath, clientUrih + '.json'), 'utf8').then(function (text) {
|
||||||
|
return JSON.parse(text);
|
||||||
|
}).then(function (data) { return data; }, function (/*err*/) { return {}; });
|
||||||
|
}
|
||||||
|
|
||||||
function loadRestHelper(myConf, pkgId) {
|
function loadRestHelper(myConf, pkgId) {
|
||||||
var pkgPath = path.join(myConf.restPath, pkgId);
|
var pkgPath = path.join(myConf.restPath, pkgId);
|
||||||
|
|
||||||
|
@ -229,6 +236,30 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return getSiteConfig(clientUrih).then(function (siteConfig) {
|
||||||
|
/*
|
||||||
|
Object.defineProperty(req, 'siteConfig', {
|
||||||
|
enumerable: true
|
||||||
|
, configurable: false
|
||||||
|
, writable: false
|
||||||
|
, value: siteConfig
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
Object.defineProperty(req, 'getSiteMailer', {
|
||||||
|
enumerable: true
|
||||||
|
, configurable: false
|
||||||
|
, writable: false
|
||||||
|
, value: function getSiteMailer() {
|
||||||
|
var nodemailer = require('nodemailer');
|
||||||
|
var transport = require('nodemailer-mailgun-transport');
|
||||||
|
//var mailconf = require('../../../com.daplie.mailer/config.mailgun');
|
||||||
|
var mailconf = siteConfig['mailgun.org'];
|
||||||
|
var mailer = PromiseA.promisifyAll(nodemailer.createTransport(transport(mailconf)));
|
||||||
|
|
||||||
|
return mailer;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (localCache.rests[pkgId]) {
|
if (localCache.rests[pkgId]) {
|
||||||
localCache.rests[pkgId].handler(req, res, next);
|
localCache.rests[pkgId].handler(req, res, next);
|
||||||
hasBeenHandled = true;
|
hasBeenHandled = true;
|
||||||
|
@ -255,5 +286,6 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue