Reputation: 1413
I am building an application in Node.js. That application runs a child process which includes a python script. I deploy my application in gcloud which shows 502-Bad Gateway (ngix). Help will be more appreciated.
Here is my code..
app.post('/webhook/', function (req, res) {
responseMessage("hi").then(function(msg){
console.log("msg ==>", msg);
res.send({response:msg});
// res.sendStatus(200)
});
})
function responseMessage(message){
var spawn = require('child_process').spawn;
var py = spawn('python3.6', ['suman.py']),
data = "suman",
dataString = 's';
data=message;
py.stdout.setEncoding('utf8');
return new Promise(function(resolve, reject){
if(data){
py.stdout.on('data', function(data){
dataString = data;
console.log('data', data);
resolve(data);
});
py.stdout.on('end', function(){
console.log('lets c',dataString);
resolve(dataString);
});
py.stdin.write(JSON.stringify(data));
py.stdin.end();
// res.end();
} else {
reject({message: 'input shouldnt be null' })
}
});
}
Server Error 502 Bad Gateway
Upvotes: 0
Views: 208