Implement API POST requests

This commit is contained in:
Jordan 2011-11-18 17:01:21 -05:00
parent a9540cb8b7
commit 95c9310be0

View file

@ -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)