mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
put POSTs into an object literal
This commit is contained in:
parent
c16d3a0f67
commit
7e522eaf85
1 changed files with 23 additions and 31 deletions
|
@ -460,6 +460,7 @@ function init(additionalSetup){
|
||||||
//create server
|
//create server
|
||||||
var app = express.createServer();
|
var app = express.createServer();
|
||||||
|
|
||||||
|
|
||||||
//load modules that needs a initalized db
|
//load modules that needs a initalized db
|
||||||
readOnlyManager = require("./db/ReadOnlyManager");
|
readOnlyManager = require("./db/ReadOnlyManager");
|
||||||
exporthtml = require("./utils/ExportHtml");
|
exporthtml = require("./utils/ExportHtml");
|
||||||
|
@ -470,6 +471,16 @@ function init(additionalSetup){
|
||||||
securityManager = require('./db/SecurityManager');
|
securityManager = require('./db/SecurityManager');
|
||||||
socketIORouter = require("./handler/SocketIORouter");
|
socketIORouter = require("./handler/SocketIORouter");
|
||||||
|
|
||||||
|
var managers = {
|
||||||
|
ro: readOnlyManager,
|
||||||
|
security: securityManager
|
||||||
|
};
|
||||||
|
var handlers = {
|
||||||
|
"export": exportHandler,
|
||||||
|
"import": importHandler,
|
||||||
|
api: apiHandler
|
||||||
|
};
|
||||||
|
|
||||||
//install logging
|
//install logging
|
||||||
var httpLogger = log4js.getLogger("http");
|
var httpLogger = log4js.getLogger("http");
|
||||||
var apiLogger = log4js.getLogger("API");
|
var apiLogger = log4js.getLogger("API");
|
||||||
|
@ -503,13 +514,8 @@ function init(additionalSetup){
|
||||||
|
|
||||||
|
|
||||||
var gets = {
|
var gets = {
|
||||||
//serve static files
|
|
||||||
'/static/*': getStatic,
|
'/static/*': getStatic,
|
||||||
|
|
||||||
//serve minified files
|
|
||||||
'/minified/:id': getMinified,
|
'/minified/:id': getMinified,
|
||||||
|
|
||||||
//serve read only pad
|
|
||||||
'/ro/:id': getRoCombinator(
|
'/ro/:id': getRoCombinator(
|
||||||
serverName,
|
serverName,
|
||||||
{ro: readOnlyManager},
|
{ro: readOnlyManager},
|
||||||
|
@ -517,45 +523,29 @@ function init(additionalSetup){
|
||||||
ERR,
|
ERR,
|
||||||
exporthtml
|
exporthtml
|
||||||
),
|
),
|
||||||
|
|
||||||
//serve pad.html under /p
|
|
||||||
'/p/:pad': sendStaticIfPad(
|
'/p/:pad': sendStaticIfPad(
|
||||||
goToPad,
|
goToPad,
|
||||||
padManager,
|
padManager,
|
||||||
path,
|
path,
|
||||||
"pad.html"
|
"pad.html"
|
||||||
)
|
)
|
||||||
|
|
||||||
//serve timeslider.html under /p/$padname/timeslider
|
|
||||||
'/p/:pad/timeslider': sendStaticIfPad(
|
'/p/:pad/timeslider': sendStaticIfPad(
|
||||||
goToPad, padManager, path, "timeslider.html"
|
goToPad, padManager, path, "timeslider.html"
|
||||||
),
|
),
|
||||||
|
|
||||||
//serve timeslider.html under /p/$padname/timeslider
|
|
||||||
//the above comment is wrong
|
|
||||||
'/p/:pad/:rev?/export/:type': getExportPadCombinator(
|
'/p/:pad/:rev?/export/:type': getExportPadCombinator(
|
||||||
goToPad, settings, hasPadAccess, exportHandler, serverName
|
goToPad, settings, hasPadAccess, exportHandler, serverName
|
||||||
),
|
|
||||||
|
|
||||||
//This is a api GET call, collect all post informations and pass it to the apiHandler
|
|
||||||
'/api/1/:func': function(req, res)
|
'/api/1/:func': function(req, res)
|
||||||
{
|
{
|
||||||
apiCaller(req, res, req.query)
|
apiCaller(req, res, req.query)
|
||||||
},
|
},
|
||||||
|
|
||||||
//serve index.html under /
|
|
||||||
'/': function(req, res)
|
'/': function(req, res)
|
||||||
{
|
{
|
||||||
return sendStatic(path, res, "index.html");
|
return sendStatic(path, res, "index.html");
|
||||||
},
|
},
|
||||||
|
|
||||||
//serve robots.txt
|
|
||||||
'/robots.txt': function(req, res)
|
'/robots.txt': function(req, res)
|
||||||
{
|
{
|
||||||
return sendStatic(path, res, "robots.txt");
|
return sendStatic(path, res, "robots.txt");
|
||||||
},
|
},
|
||||||
|
|
||||||
//serve favicon.ico
|
|
||||||
'/favicon.ico': function(req, res)
|
'/favicon.ico': function(req, res)
|
||||||
{
|
{
|
||||||
return sendStatic(path, res, "custom/favicon.ico",
|
return sendStatic(path, res, "custom/favicon.ico",
|
||||||
|
@ -570,30 +560,32 @@ function init(additionalSetup){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var posts = {};
|
var posts = {
|
||||||
|
|
||||||
//handle import requests
|
//handle import requests
|
||||||
app.post('/p/:pad/import', postImportPadCombinator(goToPad, settings, serverName, hasPadAccess, importHandler));
|
'/p/:pad/import': postImportPadCombinator(goToPad, settings, serverName, hasPadAccess, importHandler)
|
||||||
//This is a api POST call, collect all post informations and pass it to the apiHandler
|
//This is a api POST call, collect all post informations and pass it to the apiHandler
|
||||||
app.post('/api/1/:func', function(req, res)
|
'/api/1/:func': function(req, res)
|
||||||
{
|
{
|
||||||
new formidable.IncomingForm().parse(req, function(err, fields, files)
|
new formidable.IncomingForm().parse(req, function(err, fields, files)
|
||||||
{
|
{
|
||||||
apiCaller(req, res, fields)
|
apiCaller(req, res, fields)
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
|
||||||
//The Etherpad client side sends information about how a disconnect happen
|
//The Etherpad client side sends information about how a disconnect happen
|
||||||
app.post('/ep/pad/connection-diagnostic-info', logOkPostCombinator("DIAGNOSTIC-INFO", "log", "diagnosticInfo"));
|
'/ep/pad/connection-diagnostic-info': logOkPostCombinator("DIAGNOSTIC-INFO", "log", "diagnosticInfo"),
|
||||||
|
|
||||||
//The Etherpad client side sends information about client side javscript errors
|
//The Etherpad client side sends information about client side javscript errors
|
||||||
app.post('/jserror', logOkPostCombinator("CLIENT SIDE JAVASCRIPT ERROR", "error", "errorInfo"));
|
'/jserror': logOkPostCombinator("CLIENT SIDE JAVASCRIPT ERROR", "error", "errorInfo")
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
additionalSetup(app, gets);
|
additionalSetup(app, gets, posts);
|
||||||
|
|
||||||
|
|
||||||
for(var key in gets) app.get(key, gets[key]);
|
for(var key in gets) app.get(key, gets[key]);
|
||||||
|
for(var key in posts) app.post(key, posts[key]);
|
||||||
|
|
||||||
//let the server listen
|
//let the server listen
|
||||||
app.listen(settings.port, settings.ip);
|
app.listen(settings.port, settings.ip);
|
||||||
|
@ -610,4 +602,4 @@ function init(additionalSetup){
|
||||||
}
|
}
|
||||||
|
|
||||||
this.init = init;
|
this.init = init;
|
||||||
init(function(){});
|
init(function(app, gets, posts){});
|
Loading…
Add table
Add a link
Reference in a new issue