Skip to content

Instantly share code, notes, and snippets.

@labra
Last active October 9, 2017 11:14
Show Gist options
  • Save labra/271862dde85b5daf3cd011829dd74f6a to your computer and use it in GitHub Desktop.
Save labra/271862dde85b5daf3cd011829dd74f6a to your computer and use it in GitHub Desktop.
const http = require('http'),
fs = require('fs'),
url = require('url'),
qs = require('querystring');
const server = http.createServer((req, res) => {
switch (req.method) {
case 'POST':
var body = '';
req.on('data', data => { body += data;
if (body.length > 1e6) req.connection.destroy();
});
req.on('end', () => {
var POST = qs.parse(body);
res.end("Hola " + POST.cliente + "! Tu email es:" + POST.correo);
});
break;
case 'GET':
if (url.parse(req.url, true).pathname == '/') {
fs.readFile('form.html','utf8',function (err,datos) {
res.writeHead(200,'{content-type: text/html}');
res.end(datos);
});
}
break;
default:
console.log("Método no soportado" + req.method);
}
}).listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment