mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-24 21:12:10 +00:00
removed config files, just uses env vars now
This commit is contained in:
+7
-2
@@ -1,6 +1,11 @@
|
||||
const mysql = require('mysql2');
|
||||
const config = require('config');
|
||||
const pool = mysql.createPool(config.get('mysql'));
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.JAMBONES_MYSQL_HOST,
|
||||
user: process.env.JAMBONES_MYSQL_USER,
|
||||
password: process.env.JAMBONES_MYSQL_PASSWORD,
|
||||
database: process.env.JAMBONES_MYSQL_DATABASE,
|
||||
connectionLimit: process.env.JAMBONES_MYSQL_CONNECTION_LIMIT || 10
|
||||
});
|
||||
|
||||
pool.getConnection((err, conn) => {
|
||||
if (err) return console.error(err, 'Error testing pool');
|
||||
|
||||
+24
-13
@@ -1,6 +1,5 @@
|
||||
const router = require('express').Router();
|
||||
const request = require('request');
|
||||
const config = require('config');
|
||||
const {DbErrorBadRequest, DbErrorUnprocessableRequest} = require('../../utils/errors');
|
||||
const Account = require('../../models/account');
|
||||
const Webhook = require('../../models/webhook');
|
||||
@@ -13,7 +12,6 @@ const preconditions = {
|
||||
'update': validateUpdate,
|
||||
'delete': validateDelete
|
||||
};
|
||||
const API_VERSION = config.get('services.apiVersion');
|
||||
|
||||
function coerceNumbers(callInfo) {
|
||||
if (Array.isArray(callInfo)) {
|
||||
@@ -29,15 +27,25 @@ function coerceNumbers(callInfo) {
|
||||
}
|
||||
|
||||
function validateUpdateCall(opts) {
|
||||
if (!opts.call_hook && !opts.call_status && !opts.listen_status) {
|
||||
throw new DbErrorBadRequest('no valid options supplied to updateCall');
|
||||
}
|
||||
const count = [opts.call_hook, opts.call_status, opts.listen_status]
|
||||
.reduce((acc, item) => {
|
||||
if (item) return ++acc;
|
||||
}, 0);
|
||||
if (count > 1) {
|
||||
throw new DbErrorBadRequest('multiple options supplied to updateCall');
|
||||
// only one type of update can be supplied per request
|
||||
const hasWhisper = opts.whisper;
|
||||
const count = [
|
||||
'call_hook',
|
||||
'call_status',
|
||||
'listen_status',
|
||||
'mute_status']
|
||||
.reduce((acc, prop) => (opts[prop] ? ++acc : acc), 0);
|
||||
|
||||
switch (count) {
|
||||
case 0:
|
||||
// whisper is allowed on its own, or with one of the others
|
||||
if (!hasWhisper) throw new DbErrorBadRequest('no valid options supplied to updateCall');
|
||||
break;
|
||||
case 1:
|
||||
// good
|
||||
break;
|
||||
default:
|
||||
throw new DbErrorBadRequest('multiple options are not allowed in updateCall');
|
||||
}
|
||||
|
||||
if (opts.call_hook && !opts.call_hook.url) throw new DbErrorBadRequest('missing call_hook.url');
|
||||
@@ -47,6 +55,9 @@ function validateUpdateCall(opts) {
|
||||
if (opts.listen_status && !['pause', 'silence', 'resume'].includes(opts.listen_status)) {
|
||||
throw new DbErrorBadRequest('invalid listen_status');
|
||||
}
|
||||
if (opts.mute_status && !['mute', 'unmute'].includes(opts.mute_status)) {
|
||||
throw new DbErrorBadRequest('invalid mute_status');
|
||||
}
|
||||
}
|
||||
|
||||
function validateTo(to) {
|
||||
@@ -253,7 +264,7 @@ router.post('/:sid/Calls', async(req, res) => {
|
||||
const logger = req.app.locals.logger;
|
||||
|
||||
try {
|
||||
const serviceUrl = config.get('services.createCall');
|
||||
const serviceUrl = process.env.JAMBONES_CREATE_CALL_URL;
|
||||
await validateCreateCall(logger, sid, req);
|
||||
|
||||
logger.debug({payload: req.body}, `sending POST to ${serviceUrl}`);
|
||||
@@ -352,7 +363,7 @@ router.post('/:sid/Calls/:callSid', async(req, res) => {
|
||||
validateUpdateCall(req.body);
|
||||
const call = await retrieveCall(accountSid, callSid);
|
||||
if (call) {
|
||||
const url = `${call.serviceUrl}/${API_VERSION}/updateCall/${callSid}`;
|
||||
const url = `${call.serviceUrl}/${process.env.JAMBONES_API_VERSION || 'v1'}/updateCall/${callSid}`;
|
||||
logger.debug({call, url, payload: req.body}, `updateCall: retrieved call info for call sid ${callSid}`);
|
||||
request({
|
||||
url: url,
|
||||
|
||||
@@ -1212,6 +1212,8 @@ paths:
|
||||
enum:
|
||||
- pause
|
||||
- resume
|
||||
whisper:
|
||||
$ref: '#/components/schemas/Webhook'
|
||||
responses:
|
||||
202:
|
||||
description: Accepted
|
||||
|
||||
Reference in New Issue
Block a user