-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (41 loc) · 1014 Bytes
/
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
var http = require('http');
fs = require('fs');
var api_router = function(url_entry, res) {
console.log(url_entry)
fs.readFile('./api_index.html', function (err, api_html){
if (err) {
throw err;
}
res.write(api_html);
res.end();
});
}
var append_router = function(url_entry, res) {
console.log(url_entry)
fs.readFile('./append_index.html', function (err, append_html){
if (err) {
throw err;
}
res.write(append_html);
res.end();
});
}
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
if (req.url.indexOf("api") > -1) {
api_router(req.url, res);
}
else if (req.url.indexOf("submit") > -1) {
append_router(req.url, res);
}
else {
fs.readFile('./index.html', function (err, html){
if (err) {
throw err;
}
res.write(html)
res.end();
});
}
}).listen(3000, '127.0.0.1');
console.log('Server running at http://127.0.0.1');