moved GETs into an object literal

This commit is contained in:
Montana Scott Rowe 2012-01-19 17:20:26 -06:00
parent c7d4a5cf33
commit c16d3a0f67

View file

@ -502,66 +502,75 @@ function init(additionalSetup){
var gets = {}; var gets = {
//serve static files //serve static files
gets['/static/*'] = getStatic; '/static/*': getStatic,
//serve minified files //serve minified files
gets['/minified/:id'] = getMinified; '/minified/:id': getMinified,
//serve read only pad //serve read only pad
gets['/ro/:id'] = getRoCombinator( '/ro/:id': getRoCombinator(
serverName, serverName,
{ro: readOnlyManager}, {ro: readOnlyManager},
hasPadAccess, hasPadAccess,
ERR, ERR,
exporthtml exporthtml
); ),
//serve pad.html under /p //serve pad.html under /p
gets['/p/:pad'] = sendStaticIfPad( '/p/:pad': sendStaticIfPad(
goToPad, goToPad,
padManager, padManager,
path, path,
"pad.html" "pad.html"
); )
//serve timeslider.html under /p/$padname/timeslider //serve timeslider.html under /p/$padname/timeslider
gets['/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 //serve timeslider.html under /p/$padname/timeslider
//the above comment is wrong //the above comment is wrong
gets['/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 //This is a api GET call, collect all post informations and pass it to the apiHandler
gets['/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 / //serve index.html under /
gets['/'] = function(req, res) '/': function(req, res)
{ {
return sendStatic(path, res, "index.html"); return sendStatic(path, res, "index.html");
} },
//serve robots.txt //serve robots.txt
gets['/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 //serve favicon.ico
gets['/favicon.ico'] = function(req, res) '/favicon.ico': function(req, res)
{ {
return sendStatic(path, res, "custom/favicon.ico", return sendStatic(path, res, "custom/favicon.ico",
function(err){ function(err){
//there is no custom favicon, send the default favicon //there is no custom favicon, send the default favicon
if(err) if(err)
{ {
filePath = path.normalize(__dirname + "/../static/favicon.ico"); filePath = path.normalize(__dirname + "/../static/favicon.ico");
res.sendfile(filePath, { maxAge: exports.maxAge }); res.sendfile(filePath, { maxAge: exports.maxAge });
} }
}); });
}
}; };
for(var key in gets) app.get(key, gets[key]); var posts = {};
//handle import requests //handle import requests
app.post('/p/:pad/import', postImportPadCombinator(goToPad, settings, serverName, hasPadAccess, importHandler)); app.post('/p/:pad/import', postImportPadCombinator(goToPad, settings, serverName, hasPadAccess, importHandler));
@ -581,7 +590,10 @@ function init(additionalSetup){
app.post('/jserror', logOkPostCombinator("CLIENT SIDE JAVASCRIPT ERROR", "error", "errorInfo")); app.post('/jserror', logOkPostCombinator("CLIENT SIDE JAVASCRIPT ERROR", "error", "errorInfo"));
additionalSetup(); additionalSetup(app, gets);
for(var key in gets) app.get(key, gets[key]);
//let the server listen //let the server listen
app.listen(settings.port, settings.ip); app.listen(settings.port, settings.ip);