diff --git a/node/server.js b/node/server.js index a6a57497a..b502a13a0 100644 --- a/node/server.js +++ b/node/server.js @@ -196,7 +196,46 @@ async.waterfall([ res.send('Authentication required', 401); } } + + //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"); + }); + }); + //serve index.html under / + app.get('/', function(req, res) + { + var filePath = path.normalize(__dirname + "/../static/index.html"); + res.sendfile(filePath, { maxAge: exports.maxAge }); + }); + + //serve robots.txt + app.get('/robots.txt', function(req, res) + { + var filePath = path.normalize(__dirname + "/../static/robots.txt"); + res.sendfile(filePath, { maxAge: exports.maxAge }); + }); + + //serve favicon.ico + app.get('/favicon.ico', function(req, res) + { + var filePath = path.normalize(__dirname + "/../static/custom/favicon.ico"); + res.sendfile(filePath, { maxAge: exports.maxAge }, function(err) + { + //there is no custom favicon, send the default favicon + if(err) + { + filePath = path.normalize(__dirname + "/../static/favicon.ico"); + res.sendfile(filePath, { maxAge: exports.maxAge }); + } + }); + }); + //serve read only pad app.get('/ro/:id', function(req, res) { @@ -254,22 +293,22 @@ async.waterfall([ }); }); - //serve pad.html under /p - app.get('/p/:pad', function(req, res, next) + //serve pad.html under / and /p for compatibility + app.get( '(/p)?/:pad', function(req, res, next) { var filePath = path.normalize(__dirname + "/../static/pad.html"); res.sendfile(filePath, { maxAge: exports.maxAge }); }); - //serve timeslider.html under /p/$padname/timeslider - app.get('/p/:pad/timeslider', function(req, res, next) + //serve timeslider.html under /$padname/timeslider or /p/$padname/timeslider + app.get('(/p)?/:pad/timeslider', function(req, res, next) { var filePath = path.normalize(__dirname + "/../static/timeslider.html"); res.sendfile(filePath, { maxAge: exports.maxAge }); }); - //serve timeslider.html under /p/$padname/timeslider - app.get('/p/:pad/:rev?/export/:type', function(req, res, next) + //handle export requests + app.get('/:pad/:rev?/export/:type', function(req, res, next) { var types = ["pdf", "doc", "txt", "html", "odt", "dokuwiki"]; //send a 404 if we don't support this filetype @@ -296,7 +335,8 @@ async.waterfall([ }); //handle import requests - app.post('/p/:pad/import', function(req, res, next) + // app.post('/p/:pad/import', function(req, res, next) + app.post('/:pad/import', function(req, res, next) { //if abiword is disabled, skip handling this request if(settings.abiword == null) @@ -363,45 +403,6 @@ async.waterfall([ }); }); - //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"); - }); - }); - - //serve index.html under / - app.get('/', function(req, res) - { - var filePath = path.normalize(__dirname + "/../static/index.html"); - res.sendfile(filePath, { maxAge: exports.maxAge }); - }); - - //serve robots.txt - app.get('/robots.txt', function(req, res) - { - var filePath = path.normalize(__dirname + "/../static/robots.txt"); - res.sendfile(filePath, { maxAge: exports.maxAge }); - }); - - //serve favicon.ico - app.get('/favicon.ico', function(req, res) - { - var filePath = path.normalize(__dirname + "/../static/custom/favicon.ico"); - res.sendfile(filePath, { maxAge: exports.maxAge }, function(err) - { - //there is no custom favicon, send the default favicon - if(err) - { - filePath = path.normalize(__dirname + "/../static/favicon.ico"); - res.sendfile(filePath, { maxAge: exports.maxAge }); - } - }); - }); - //let the server listen app.listen(settings.port, settings.ip); console.log("Server is listening at " + settings.ip + ":" + settings.port); diff --git a/static/js/pad_impexp.js b/static/js/pad_impexp.js index 0037195f2..76e994f16 100644 --- a/static/js/pad_impexp.js +++ b/static/js/pad_impexp.js @@ -240,9 +240,9 @@ var padimpexp = (function() { pad = _pad; - //get /p/padname - var pad_root_path = new RegExp(/.*\/p\/[^\/]+/).exec(document.location.pathname) - //get http://example.com/p/padname + //get /p/padname or /padname + var pad_root_path = new RegExp(/.*\/[^\/]+/).exec(document.location.pathname) + //get http://example.com/p/padname or http://example.com/padname var pad_root_url = document.location.href.replace(document.location.pathname, pad_root_path) // build the export links