forked from ZeroSharp/serverless-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
43 lines (32 loc) · 963 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
40
41
42
43
'use strict';
var child_process = require('child_process');
module.exports.hello = (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' } ]);
proc.stdout.on('data', function (data) {
var dataStr = data.toString()
// console.log('stdout: ' + dataStr);
strToReturn += dataStr
});
proc.stderr.on('data', function (data) {
console.log(`stderr: ${data}`);
});
proc.on('close', function(code) {
if(code !== 0) {
return callback(new Error(`Process exited with non-zero status code ${code}`));
}
const response = {
statusCode: 200,
body: JSON.stringify({
message: strToReturn,
// input: event,
}),
};
callback(null, response);
});
};