-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (25 loc) · 826 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
33
34
var __port = "8888";
var http = require("http");
var url = require("url");
function start( route, handle )
{
function onRequest( request, response )
{
var post_data = "";
var pathname = url.parse(request.url).pathname;
console.log("Request received for " + pathname);
request.setEncoding("utf-8");
request.addListener("data", function( post_data_chunk )
{
post_data += post_data_chunk;
console.log("Received POST data chunk '" + post_data_chunk + "'");
});
request.addListener("end", function()
{
route(handle, pathname, response, post_data);
});
}
http.createServer(onRequest).listen(__port);
console.log("node.js server has started on port " + __port);
}
exports.start = start;