diff options
author | Egil Moeller <egil.moller@freecode.no> | 2012-02-25 15:20:31 +0100 |
---|---|---|
committer | Egil Moeller <egil.moller@freecode.no> | 2012-02-25 15:20:31 +0100 |
commit | a5245c896aa6f89a855f7b3603fbb1e48fb06f64 (patch) | |
tree | 097a95e4ca1b5fcbcc0f628eb2e98b9473cf34c7 | |
parent | fe7bed650164dde9a3ed736b8d1117f1054e0919 (diff) | |
download | etherpad-lite-a5245c896aa6f89a855f7b3603fbb1e48fb06f64.zip |
Moved apicalls
-rw-r--r-- | node/apicalls.js | 58 | ||||
-rw-r--r-- | node/server.js | 61 | ||||
-rw-r--r-- | pluginomatic.json | 3 |
3 files changed, 60 insertions, 62 deletions
diff --git a/node/apicalls.js b/node/apicalls.js new file mode 100644 index 00000000..183f4411 --- /dev/null +++ b/node/apicalls.js @@ -0,0 +1,58 @@ +var log4js = require('log4js'); +var apiLogger = log4js.getLogger("API"); +var apiHandler = require('./handler/APIHandler'); +var formidable = require('formidable'); + +//This is for making an api call, collecting all post information and passing it to the apiHandler +exports.apiCaller = function(req, res, fields) { + res.header("Content-Type", "application/json; charset=utf-8"); + + 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); +} + + +exports.expressCreateServer = function (hook_name, args, cb) { + //This is a api GET call, collect all post informations and pass it to the apiHandler + args.app.get('/api/1/:func', function (req, res) { + apiCaller(req, res, req.query) + }); + + //This is a api POST call, collect all post informations and pass it to the apiHandler + args.app.post('/api/1/:func', function(req, res) { + new formidable.IncomingForm().parse(req, function (err, fields, files) { + apiCaller(req, res, fields) + }); + }); + + //The Etherpad client side sends information about how a disconnect happen + args.app.post('/ep/pad/connection-diagnostic-info', function(req, res) { + new formidable.IncomingForm().parse(req, function(err, fields, files) { + console.log("DIAGNOSTIC-INFO: " + fields.diagnosticInfo); + res.end("OK"); + }); + }); + + //The Etherpad client side sends information about client side javscript errors + args.app.post('/jserror', function(req, res) { + new formidable.IncomingForm().parse(req, function(err, fields, files) { + console.error("CLIENT SIDE JAVASCRIPT ERROR: " + fields.errorInfo); + res.end("OK"); + }); + }); +}
\ No newline at end of file diff --git a/node/server.js b/node/server.js index 080d4c1a..fec7668c 100644 --- a/node/server.js +++ b/node/server.js @@ -161,67 +161,6 @@ async.waterfall([ }); }); - var apiLogger = log4js.getLogger("API"); - - //This is for making an api call, collecting all post information and passing it to the apiHandler - var apiCaller = function(req, res, fields) - { - res.header("Content-Type", "application/json; charset=utf-8"); - - 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); - } - - //This is a api GET call, collect all post informations and pass it to the apiHandler - app.get('/api/1/:func', function(req, res) - { - apiCaller(req, res, req.query) - }); - - //This is a api POST call, collect all post informations and pass it to the apiHandler - app.post('/api/1/:func', function(req, res) - { - new formidable.IncomingForm().parse(req, function(err, fields, files) - { - apiCaller(req, res, fields) - }); - }); - - //The Etherpad client side sends information about how a disconnect happen - app.post('/ep/pad/connection-diagnostic-info', function(req, res) - { - new formidable.IncomingForm().parse(req, function(err, fields, files) - { - console.log("DIAGNOSTIC-INFO: " + fields.diagnosticInfo); - res.end("OK"); - }); - }); - - //The Etherpad client side sends information about client side javscript errors - app.post('/jserror', function(req, res) - { - new formidable.IncomingForm().parse(req, function(err, fields, files) - { - console.error("CLIENT SIDE JAVASCRIPT ERROR: " + fields.errorInfo); - res.end("OK"); - }); - }); //let the server listen app.listen(settings.port, settings.ip); diff --git a/pluginomatic.json b/pluginomatic.json index 237f5c64..498384e2 100644 --- a/pluginomatic.json +++ b/pluginomatic.json @@ -5,7 +5,8 @@ { "name": "padurlsanitize", "hooks": { "expressCreateServer": "../padurlsanitize:expressServer" } }, { "name": "minified", "hooks": { "expressCreateServer": "../minified:expressServer" } }, { "name": "padreadonly", "hooks": { "expressCreateServer": "../padreadonly:expressServer" } }, - { "name": "webaccess", "hooks": { "expressConfigure": "../webaccess:expressConfigure" } } + { "name": "webaccess", "hooks": { "expressConfigure": "../webaccess:expressConfigure" } }, + { "name": "apicalls", "hooks": { "expressCreateServer": "../apicalls:expressCreateServer" } } ] } |