-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
39 lines (27 loc) · 883 Bytes
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var child_process = require('child_process');
module.exports.nextBus = (event, context, callback) => {
var strToReturn = '';
var php = './php';
// workaround to get 'sls invoke local' to work
if (typeof process.env.PWD !== "undefined") {
php = 'php';
}
var proc = child_process.spawn(php, [ "index.php", JSON.stringify(event), { stdio: 'inherit' } ]);
var dataStr = '';
proc.stdout.on('data', function (data) {
dataStr = data.toString();
strToReturn += dataStr;
});
proc.stderr.on('data', function (data) {
console.log(`stderr: ${data}`);
});
proc.on('close', function(code) {
if(code !== 0) {
console.log('stdout: ' + dataStr);
return callback(new Error(`Process exited with non-zero status code ${code}`));
}
const response = JSON.parse(strToReturn);
callback(null, response);
});
};