mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-04 14:19:13 -04:00
Implement API POST requests
This commit is contained in:
parent
a9540cb8b7
commit
95c9310be0
1 changed files with 29 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue