code / app /nodejs /index.js
edwagbb's picture
Update app/nodejs/index.js
21f8e20 verified
raw
history blame
673 Bytes
require('http').createServer(async(res,req)=>{
var urlObject = new URL('http://' + req.headers['host'] + req.url)
var code = querystring.parse(urlObject.search.length > 1 ? urlObject.search.substr(1) : "");
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)=>{${code}}`)(res,req);
if(resp && !res.finished ) return res.end(""+resp);
}).listen(7860)