mirror of https://github.com/lukechilds/Agama.git
pbca26
7 years ago
3 changed files with 40 additions and 5 deletions
@ -1,13 +1,38 @@ |
|||||
|
const request = require('request'); |
||||
|
|
||||
module.exports = (shepherd) => { |
module.exports = (shepherd) => { |
||||
// payload
|
// payload
|
||||
// record all calls
|
// record all calls
|
||||
shepherd.get('/mm/request', (req, res, next) => { |
shepherd.post('/mm/request', (req, res, next) => { |
||||
const successObj = { |
let _payload = req.body.payload; |
||||
msg: 'success', |
_payload.userpass = shepherd.mmupass; |
||||
result: 'started', |
const options = { |
||||
|
url: `http://localhost:7783`, |
||||
|
method: 'POST', |
||||
|
body: JSON.stringify(_payload), |
||||
}; |
}; |
||||
|
|
||||
res.end(JSON.stringify(successObj)); |
shepherd.log(_payload); |
||||
|
|
||||
|
// send back body on both success and error
|
||||
|
// this bit replicates iguana core's behaviour
|
||||
|
request(options, (error, response, body) => { |
||||
|
if (response && |
||||
|
response.statusCode && |
||||
|
response.statusCode === 200) { |
||||
|
const _parsedBody = JSON.parse(body); |
||||
|
shepherd.mmPublic[_payload.mapToProp] = _parsedBody; |
||||
|
res.end(body); |
||||
|
} else { |
||||
|
res.end(body ? body : JSON.stringify({ |
||||
|
result: 'error', |
||||
|
error: { |
||||
|
code: -777, |
||||
|
message: `unable to call method ${_payload.method} at port 7783`, |
||||
|
}, |
||||
|
})); |
||||
|
} |
||||
|
}); |
||||
}); |
}); |
||||
|
|
||||
return shepherd; |
return shepherd; |
||||
|
Loading…
Reference in new issue