From 95c9310be00b5c8f02ccc2004cca924fff5a1d15 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 18 Nov 2011 17:01:21 -0500 Subject: [PATCH] Implement API POST requests --- node/server.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/node/server.js b/node/server.js index 57609ac80..83e6a7f98 100644 --- a/node/server.js +++ b/node/server.js @@ -316,6 +316,35 @@ async.waterfall([ //call the api handler apiHandler.handle(req.params.func, req.query, req, res); }); + + //This is a api call, collect all post informations and pass it to the apiHandler + app.post('/api/1/:func', function(req, res) + { + res.header("Server", serverName); + res.header("Content-Type", "application/json; charset=utf-8"); + + new formidable.IncomingForm().parse(req, function(err, fields, files) + { + apiLogger.info("REQUEST, " + req.params.func + ", " + JSON.stringify(fields)); + + //wrap the send function so we can log the response + res._send = res.send; + res.send = function(response) + { + response = JSON.stringify(response); + apiLogger.info("RESPONSE, " + req.params.func + ", " + response); + + //is this a jsonp call, if yes, add the function call + if(req.query.jsonp) + response = req.query.jsonp + "(" + response + ")"; + + res._send(response); + } + + //call the api handler + apiHandler.handle(req.params.func, fields, req, res); + }); + }); //The Etherpad client side sends information about how a disconnect happen app.post('/ep/pad/connection-diagnostic-info', function(req, res)