-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (24 loc) · 819 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
var http = require("http");
var url = require("url");
var requestHandlers = require("./requestHandler");
var handle = {}
handle["/"] = requestHandlers.index;
handle["/BaseNotificationServer"] = requestHandlers.notify;
function start(port) {
function onRequest(request, response) {
var pathname = url.parse(request.url).pathname;
console.log("Receive request for " + pathname);
if (typeof handle[pathname] === 'function') {
handle[pathname](response);
response.end();
} else {
console.log("No request handle found for " + pathname);
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not found");
response.end();
}
}
http.createServer(onRequest).listen(port);
console.log("Server has started.");
}
exports.start = start;