summaryrefslogtreecommitdiffstats
path: root/tinyserver.js
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2012-06-29 23:39:29 -0500
committerKyle Kaminski <kyle@kkaminsk.com>2012-06-29 23:39:29 -0500
commita1d9689c5df0bdaf49a42e4682742e344665791a (patch)
tree3ee92c36cc55e41f279ab8ee7aaab83daa739548 /tinyserver.js
parent14f7c610cbf281b5f5776b84b452baf5dfc31f52 (diff)
downloadfubar-a1d9689c5df0bdaf49a42e4682742e344665791a.tar.gz
fubar-a1d9689c5df0bdaf49a42e4682742e344665791a.tar.bz2
fubar-a1d9689c5df0bdaf49a42e4682742e344665791a.zip
work more on this, what more can I say
Diffstat (limited to 'tinyserver.js')
-rw-r--r--tinyserver.js21
1 files changed, 15 insertions, 6 deletions
diff --git a/tinyserver.js b/tinyserver.js
index fd9d37d..ac2560b 100644
--- a/tinyserver.js
+++ b/tinyserver.js
@@ -1,3 +1,12 @@
+/*
+ * tinyserver.js
+ *
+ * author: Kyle
+ *
+ * teh server, what else is new?
+ *
+ */
+
var http = require('http');
var util = require('util');
var url = require('url');
@@ -14,26 +23,26 @@ var activeUsers = [];
/* this function is poked upon 'request' event */
function requestListener(req, res) {
- var datareq = '';
+ var reqdata = ''; /* for POST data */
- req.on('data', function(chunk) { datareq += chunk; } );
+ req.on('data', function(chunk) { reqdata += chunk; } );
+ req.on('close', function() { util.log('[reqlistener] client terminated before we could respond'); });
req.on('end', function() {
- util.log('[reqlistener] finished recv data');
- //console.log('data: %s', datareq.length == 0 ? 'empty' : datareq);
+ util.log(util.format('[reqlistener] finished recv data%s', (reqdata.length == 0) ? '' : ', got ' + reqdata.length + ' bytes'));
/* should be some logic, e.g. blueprint 1 */
util.log('[reqlistener] request kind: ' + req.method);
/* routing for pathname, figure out what request we have */
var urlquery = url.parse(req.url);
//console.log('[reqlistener] query dump:\n' + util.inspect(urlquery));
- router.route(urlquery, res);
+ router.route(urlquery, reqdata, res);
});
- req.on('close', function() { util.log('[reqlistener] client terminated before we could respond'); });
}
var server = http.createServer(requestListener);
server.listen(serverConfig.port, serverConfig.hostname, function() {
/* could use for proxy stuff? this function is called when listening event is emitted */
+ util.log('[server] listening on port ' + serverConfig.port);
});
server.on('connection', function(socket) {