change api calls from POST to GET

pull/85/merge
Peter 'Pita' Martischka 2011-08-08 20:14:01 +01:00
parent 9d91a3873c
commit a6df6ab0a7
1 changed files with 12 additions and 26 deletions

View File

@ -243,37 +243,23 @@ async.waterfall([
var apiLogger = log4js.getLogger("API");
//This is a api call, collect all post informations and pass it to the apiHandler
app.all('/api/1/:func', function(req, res)
app.get('/api/1/:func', function(req, res)
{
res.header("Server", serverName);
//check if this is a post request
if(req.method == "POST")
apiLogger.info("REQUEST, " + req.params.func + ", " + JSON.stringify(req.query));
//wrap the send function so we can log the response
res._send = res.send;
res.send = function(response)
{
new formidable.IncomingForm().parse(req, function(err, fields, files)
{
if(err) throw err;
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);
res._send(response);
}
//call the api handler
apiHandler.handle(req.params.func, fields, req, res);
});
}
//say goodbye if this is not a post request
else
{
res.send({code: 5, message: "no POST request", data: null});
response = JSON.stringify(response);
apiLogger.info("RESPONSE, " + req.params.func + ", " + response);
res._send(response);
}
//call the api handler
apiHandler.handle(req.params.func, req.query, req, res);
});
//The Etherpad client side sends information about how a disconnect happen