forked from kat4/commit4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.js
38 lines (32 loc) · 891 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
34
35
36
37
38
var fs = require('fs');
var index = fs.readFileSync('./views/index.html');
var githubHandler = require('./githubrequest.js');
var handlers = module.exports = {};
var headers = {
'content-type' : 'text/html'
};
handlers.home = function(req, res){
res.writeHead(200, headers);
res.end(index);
};
handlers.commit4 = function(req, res){
githubHandler(req,res);
};
handlers.notFound = function(req, res){
res.writeHead(404, headers);
res.end('Resource not found');
};
handlers.general = function(req, res) {
fs.readFile("./public" + req.url, function(err, file) {
if (err) {
console.log('errrr', err);
handlers.notFound(req, res);
} else {
var ext = req.url.split(".")[1];
res.writeHead(200, {
'Content-type': 'text/' + ext
});
res.end(file);
}
});
};