-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (30 loc) · 1.17 KB
/
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
var http = require('http'),
prepReq = require('./lib/prep-req'),
prepRes = require('./lib/prep-res');
module.exports = (function() {
var public = {};
public.start = function (options) {
var server = http.createServer(function (req, res) {
res = prepRes(req, res);
req = prepReq(req, res, options.handlers);
var response = null, code = 200, complete = function(response) {
res.end(JSON.stringify(response));
};
// executeResponse only exists if we can handle the request
// and we have everything we need to do so. It comes from
// prepReq
if (req.executeResponse) {
req.executeResponse(res, complete);
} else {
code = 404;
response = {status: 404, description: 'maybe its because im irish'}
complete(response);
}
});
//Lets start our server
server.listen(options.port, function() {
console.log("Server listening on: http://localhost:%s", options.port);
});
}
return public;
})()