Commit 48a5c004b3ad397d0a4f410f1de2a0be15564453

Authored by Adhidarma Hadiwinoto
1 parent c5a0b86218
Exists in master

MIgration message from config.handler_callback_server to config.apiserver

Showing 1 changed file with 15 additions and 5 deletions Side-by-side Diff

lib/apiserver/index.js
... ... @@ -20,11 +20,15 @@ const history = require('../history');
20 20  
21 21 const routerModems = require('./router-modems');
22 22  
  23 +if (config.handler_callback_server) {
  24 + logger.warn('Deprecated config.handler_callback_server. Please migrate it to config.apiserver!');
  25 +}
  26 +
23 27 const app = express();
24 28 messagingService.setTransport(transport);
25 29  
26 30 function apikeyChecker(req, res, next) {
27   - res.locals.has_valid_apikey = req.params.apikey === config.handler_callback_server.apikey;
  31 + res.locals.has_valid_apikey = req.params.apikey === (config.apiserver.apikey || config.handler_callback_server.apikey);
28 32 if (res.locals.has_valid_apikey) {
29 33 next();
30 34 }
... ... @@ -110,7 +114,13 @@ app.get('/apikey/:apikey/on-sms/inbox', onIncomingSms);
110 114 app.get('/apikey/:apikey/history', pageHistory);
111 115 app.use('/apikey/:apikey/modems', routerModems);
112 116  
113   -const listenPort = config && config.handler_callback_server ? config.handler_callback_server.listen_port : null;
114   -listenPort && app.listen(listenPort, () => {
115   - logger.info('HTTP Handler Callback server listening on port ' + listenPort);
116   -})
117 117 \ No newline at end of file
  118 +const listenPort = (config && config.apiserver && config.apiserver.listen_port ? config.apiserver.listen_port : null)
  119 + || (config && config.handler_callback_server ? config.handler_callback_server.listen_port : null);
  120 +
  121 +if (listenPort) {
  122 + app.listen(listenPort, () => {
  123 + logger.info('HTTP Handler Callback server listening on port ' + listenPort);
  124 + });
  125 +} else {
  126 + logger.warn('Undefined config.apiserver.listen_port for APISERVER. Not listening for command.');
  127 +}