-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
executable file
·32 lines (26 loc) · 911 Bytes
/
server.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
#!/usr/bin/env node
var http = require("http");
var url = require("url");
var conf = require("./server/conf");
var router = require("./server/router");
function handleRequest(request, response) {
var postData = "";
var pathname = url.parse(request.url).pathname;
//console.log("Request for " + pathname + " received.");
request.setEncoding("utf8");
request.addListener("data", function(postDataChunk) {
postData += postDataChunk;
console.log("Received POST data chunk '" + postDataChunk + "'.");
});
request.addListener("end", function() {
router.route(pathname, request, response, postData);
});
};
if (conf.production) {
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});
}
http.createServer(handleRequest).listen(process.env.PORT || conf.port);
console.log("Listening on port " + conf.port);
// vi: set et sta sw=2 ts=2: