Compare View
Commits (8)
Changes
Showing 3 changed files Side-by-side Diff
gateway/advice-push-server.js
... | ... | @@ -8,8 +8,6 @@ const config = require('../config'); |
8 | 8 | const logger = require('../logger'); |
9 | 9 | const matrix = require('../matrix'); |
10 | 10 | |
11 | -if (!config || !config.push_server || !!config.push_server.apikey || !config.push_server.advice || !config.push_server.advice.url || !config.push_server.advice.port) return; | |
12 | - | |
13 | 11 | const app = express(); |
14 | 12 | |
15 | 13 | let partner = null; |
... | ... | @@ -17,13 +15,17 @@ let partner = null; |
17 | 15 | function setPartner(_partner) { |
18 | 16 | partner = _partner; |
19 | 17 | |
18 | + if (!config || !config.push_server || !config.push_server.apikey || !config.push_server.advice || !config.push_server.advice.url || !config.push_server.advice.port) { | |
19 | + return; | |
20 | + } | |
21 | + | |
20 | 22 | app.listen(config.push_server.advice.port, function () { |
21 | 23 | logger.info('Advice server listening', {port: config.push_server.advice.port}); |
22 | 24 | }); |
23 | 25 | } |
24 | 26 | |
25 | 27 | function isValidApikey(req, res, next) { |
26 | - if (req.params.apikey === config.push_server.apikey) { | |
28 | + if (config.push_server && config.push_server.apikey && (req.params.apikey === config.push_server.apikey)) { | |
27 | 29 | next(); |
28 | 30 | } |
29 | 31 | else { |
... | ... | @@ -45,16 +47,9 @@ function adviceHandler(req, res, next) { |
45 | 47 | return; |
46 | 48 | } |
47 | 49 | |
48 | - let task = null; | |
49 | - | |
50 | - try { | |
51 | - task = JSON.parse(coreMessage); | |
52 | - } | |
53 | - catch(e) { | |
54 | - logger.warn('PUSH-ADVICE: Exception on parsing task to advice', {err: e}); | |
55 | - } | |
50 | + let task = req.body; | |
56 | 51 | |
57 | - if (!task) { | |
52 | + if (!task || !task.trx_id || !task.destination || !task.product) { | |
58 | 53 | logger.warn('PUSH-ADVICE: Invalid task'); |
59 | 54 | res.end('INVALID_TASK'); |
60 | 55 | return; |
gateway/pull.js