Last active
October 9, 2017 11:14
-
-
Save labra/271862dde85b5daf3cd011829dd74f6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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