code / app /nodejs /index.js
edwagbb's picture
Update app/nodejs/index.js
89caef8 verified
raw
history blame contribute delete
701 Bytes
require('http').createServer(async(res,req)=>{
var urlObject = new URL('http://127.0.0.1' + req.url)
var code = require('querystring').parse(urlObject.search.length > 1 ? urlObject.search.substr(1) : "")['code'];
if(!code){
code = await new Promise((resolve) => {
let body = [];
req.on('data', chunk => {
body.push(chunk);
}).on('end', () => {
resolve(Buffer.concat(body).toString());
}).on('error', () => {
resolve(Buffer.concat(body).toString());
})
})
}
if(!code) return res.end('no code!');
var resp = await eval(`async(res,req)=>{return (${code})}`)(res,req);
if(!res.finished ) return res.end(""+resp);
}).listen(parseInt(process.argv[2]))