-
Notifications
You must be signed in to change notification settings - Fork 16
/
handlers.js
33 lines (29 loc) · 1006 Bytes
/
handlers.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
var fs = require('fs');
var path = require('path');
var handlers = module.exports = {};
handlers.serveLanding = function(request, response) {
fs.readFile(path.join(__dirname, '../..', 'index.html'), function(err, file) {
if (err) throw err;
response.writeHead(200, { "content-type": "text/html" });
response.end(file);
});
}
handlers.servePublic = function(request, response) {
fs.readFile(path.join(__dirname, '../..', request.url), function(err, file) {
if (err) throw err;
var extension = request.url.split('.')[1];
var extensionType = {
"html": "text/html",
"css": "text/css",
"js": "application/javascript",
"ico": "image/x-icon"
}
response.writeHead(200, { "content-type": extensionType[extension] });
response.end(file);
});
}
handlers.pageNotFound = function(request, response) {
response.writeHead(404, { "content-type": "text/html" });
response.write('<h1>404 Page Requested Cannot be Found</h1>');
response.end();
}