forked from cursosLabra/EjemploNode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path56_corrector.js
37 lines (34 loc) · 1008 Bytes
/
56_corrector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const http = require('http'),
fs = require('fs'),
url = require('url'),
qs = require('querystring');
const server = http.createServer(function(req, res) {
switch (req.method) {
case 'POST':
var body = '';
req.on('data', function(data) {
body += data;
if (body.length > 1e6)
req.connection.destroy();
});
req.on('end', function() {
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 == '/') {
datos = "<form action=\"procesa\" method=\"POST\">"
+ "<label>Nombre: <input name=\"cliente\"></label><br>"
+ "<label>Email: <input name=\"correo\" type=\"email\"></label><br>"
+ "<button>Enviar</button></form>"
res.end(datos);
}
break;
default:
console.log("Método no soportado" + req.method);
}
});
server.listen(3000);
console.log('Server listenning at port 3000');