-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.js
39 lines (35 loc) · 974 Bytes
/
routes.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
const url = require('url');
let fs = require('fs');
html = {
render(path, response) {
fs.readFile(path, null, function (error, data) {
if (error) {
response.writeHead(404);
respone.write('file not found');
} else {
response.write(data);
}
response.end();
});
}
}
module.exports = {
handleRequest(request, response) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
let path = url.parse(request.url).pathname;
switch (path) {
case '/':
html.render('./index.html', response);
break;
case '/login':
html.render('./about.html', response);
break;
default:
response.writeHead(404);
response.write('Route not found');
response.end();
}
}
}