Open stephenjesus opened 5 years ago
const compileUrl: string = 'https://run.glot.io';
const post_options: any = {
// host: compileUrl,
url : 'https://run.glot.io/languages/python/latest',
method: 'POST',
json: true,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Token f4410576-e492-4dc9-8e9a-b7d5c14f2001',
},
body : JSON.stringify({"files": [{"name": "main.py", "content": "print(42)"}]})
};
logger.info(post_options , 'post options');
const post_req = http.request(post_options, (res: any) => {
res.setEncoding('utf8');
let compilerdata = '';
res.on('data', (chunk: any) => {
compilerdata += chunk;
});
res.on('end', () => {
if (payload) {
try {
const output = JSON.parse(compilerdata);
output.output ? (output.output = JSON.parse(output.output)) : '';
output.errors ? (output.errors = JSON.parse(output.errors)) : '';
resolve(JSON.stringify(output));
} catch (err) {
const tempObj = {
success: false,
message: err
};
resolve(JSON.stringify(tempObj));
}
} else {
const tempObj = {
success: false,
message: 'No data from compiler'
};
resolve(JSON.stringify(tempObj));
}
});
}).on('error', (err: any) => {
logger.info(err);
const tempObj = {
success: false,
message: 'Error Occurred'
};
resolve(JSON.stringify(tempObj));
});
post_req.write(payload.toString());
post_req.end();
});
when i tried curl command for python is working fine...but i tried to integrate in node js it shows some connection issue.. { message: 'connect ECONNREFUSED 127.0.0.1:443', stack: 'Error: connect ECONNREFUSED 127.0.0.1:443\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)', errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 44 @prasmussen @javierprovecho