remove config in favor of env vars, other major changes

This commit is contained in:
Dave Horton
2020-02-15 22:03:28 -05:00
parent 3d24ac1914
commit 3c89b7fd76
14 changed files with 162 additions and 113 deletions

View File

@@ -6,7 +6,7 @@ const makeTask = require('./tasks/make_task');
const normalizeJamones = require('./utils/normalize-jamones');
module.exports = function(srf, logger) {
const {lookupAppByPhoneNumber, lookupApplicationBySid} = srf.locals.dbHelpers;
const {lookupAppByPhoneNumber, lookupAppBySid, lookupAppByRealm} = srf.locals.dbHelpers;
function initLocals(req, res, next) {
const callSid = uuidv4();
@@ -19,6 +19,8 @@ module.exports = function(srf, logger) {
req.locals.logger.debug(`got application from X-Application-Sid header: ${application_sid}`);
req.locals.application_sid = application_sid;
}
if (req.has('X-Authenticated-User')) req.locals.originatingUser = req.get('X-Authenticated-User');
next();
}
@@ -50,7 +52,17 @@ module.exports = function(srf, logger) {
const logger = req.locals.logger;
try {
let app;
if (req.locals.application_sid) app = await lookupApplicationBySid(req.locals.application_sid);
if (req.locals.application_sid) app = await lookupAppBySid(req.locals.application_sid);
else if (req.locals.originatingUser) {
const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
if (arr) {
const sipRealm = arr[2];
logger.debug(`looking for device calling app for realm ${sipRealm}`);
app = await lookupAppByRealm(sipRealm);
if (app) logger.debug({app}, `retrieved device calling app for realm ${sipRealm}`);
}
}
else app = await lookupAppByPhoneNumber(req.locals.calledNumber);
if (!app || !app.call_hook || !app.call_hook.url) {
@@ -66,8 +78,8 @@ module.exports = function(srf, logger) {
* create a requestor that we will use for all http requests we make during the call.
* also create a notifier for call status events (if not needed, its a no-op).
*/
app.requestor = new Requestor(this.logger, app.call_hook);
if (app.call_status_hook) app.notifier = new Requestor(this.logger, app.call_status_hook);
app.requestor = new Requestor(logger, app.call_hook);
if (app.call_status_hook) app.notifier = new Requestor(logger, app.call_status_hook);
else app.notifier = {request: () => {}};
req.locals.application = app;