-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (37 loc) · 1.1 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
const Server = require('./server');
const path = require('path');
const fs = require('fs');
var server = new Server;
server.get('/', function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World');
res.end();
});
server.get('/me', function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello It\'s me');
res.end();
});
server.get('/submit', function(req, res) {
file = path.join(__dirname + '/views/form.html');
fs.readFile(file, function(err, data){
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
});
server.post('/process-submit', function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
req.setEncoding("utf8");
var postData = '';
req.addListener("data", function(postDataChunk) {
postData += postDataChunk;
console.log("Received POST data chunk '"+
postDataChunk + "'.");
});
req.addListener("end", function() {
res.write(postData);
res.end();
});
});
server.start();