-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.js
More file actions
74 lines (61 loc) · 2.32 KB
/
form.js
File metadata and controls
74 lines (61 loc) · 2.32 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const http = require('http');
const arg = process.argv;
const fs = require('fs');
const queryString = require('querystring');
http.createServer((req, res) => {
fs.readFile('html/web.html', 'utf-8', (err, data) => {
if (err) {
res.writeHead(500, { "content-type": 'text/plain' });
res.end('Internal server error');
return;
}
if (req.url == '/') {
res.writeHead(200, { "content-type": 'text/html' });
res.write(data);
res.end();
}
else if (req.url == '/submit') {
let dataBody = [];
req.on('data', (chunk) => {
dataBody.push(chunk);
});
req.on('end', () => {
let rawData = Buffer.concat(dataBody).toString();
let readableData = queryString.parse(rawData);
console.log(readableData);
fs.readFile('html/admin-dashboard.html', 'utf-8', (err, dashboardData) => {
if (err) {
res.writeHead(500, { "content-type": 'text/plain' });
res.end('internal server error');
return;
}
res.writeHead(200, { "content-type": 'text/html' });
// res.write(`<h1>Logged In Successfully!</h1>`);
// res.write(`<p>Email: ${readableData.email}</p>`);
// res.write(`<p>Password: ${readableData.password}</p>`);
res.write(dashboardData);
res.end();
});
});
}
else {
res.writeHead(404, { "content-type": 'text/plain' });
res.end('Page Not Found');
}
});
}).listen(arg[2]);
// http.createServer((req, res) => {
// res.writeHead(200, { "content-type": 'text/html' });
// if (req.url == '/') {
// res.write(`
// <form action='/submit' method="post" >
// <input type="text" placeholder='Enter name' name='name' />
// <input type="email" placeholder='Enter email' name='email' />
// <button>Submit</button>
// </form>
// `)
// } else if (req.url == '/submit') {
// res.write('<h1>Data Submitted</h1>')
// }
// res.end();
// }).listen(arg[2]);