-
Notifications
You must be signed in to change notification settings - Fork 26
/
app.js
31 lines (25 loc) · 809 Bytes
/
app.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
var http = require('http');
var url = require('url');
var fs = require('fs');
var newPostFormHTML = fs.readFileSync('views/post/new.html');
function renderNewPostForm(request, response) {
response.writeHead(200, {
'Content-type': 'text/html; charset=utf-8'
});
response.end(newPostFormHTML);
}
function render404(request, response) {
response.writeHead(404);
response.end('404 File not found');
}
var server = http.createServer(function(request, response) {
var newPostFormRegex = new RegExp('^/posts/new/?$');
var pathname = url.parse(request.url).pathname;
if (newPostFormRegex.test(pathname)) {
renderNewPostForm(request, response);
} else {
render404(request, response);
}
});
server.listen(8000);
console.log('Listening on http://127.0.0.1:8000');