Document saving almost working

This commit is contained in:
John Crepezzi 2011-11-18 10:49:00 -05:00
commit 7756e38595
3 changed files with 63 additions and 14 deletions

View file

@ -50,9 +50,43 @@ StaticHandler.prototype.handle = function(request, response) {
///////////
var documents = {};
var DocumentHandler = function() {
};
DocumentHandler.prototype.handle = function(request, response) {
if (request.method == 'GET') {
}
else if (request.method == 'POST') {
var key = '123';
request.on('data', function(data) {
if (!documents[key]) {
documents[key] = '';
}
documents[key] += data.toString();
});
request.on('end', function(end) {
response.end(JSON.stringify({ uuid: key }));
});
}
};
///////////
http.createServer(function(request, response) {
var handler = new StaticHandler('./static');
handler.handle(request, response);
var incoming = url.parse(request.url, false);
if (incoming.pathname.indexOf('/documents') === 0) {
var handler = new DocumentHandler();
handler.handle(request, response);
}
else {
var handler = new StaticHandler('./static');
handler.handle(request, response);
}
}).listen(7777);