This commit is contained in:
GitHub Merge Button 2012-02-18 09:51:42 -08:00
commit 7d643f911f
2 changed files with 50 additions and 49 deletions

View file

@ -197,6 +197,45 @@ 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 });
}
});
});
//serve read only pad //serve read only pad
app.get('/ro/:id', function(req, res) app.get('/ro/:id', function(req, res)
{ {
@ -254,22 +293,22 @@ async.waterfall([
}); });
}); });
//serve pad.html under /p //serve pad.html under / and /p for compatibility
app.get('/p/:pad', function(req, res, next) app.get( '(/p)?/:pad', function(req, res, next)
{ {
var filePath = path.normalize(__dirname + "/../static/pad.html"); var filePath = path.normalize(__dirname + "/../static/pad.html");
res.sendfile(filePath, { maxAge: exports.maxAge }); res.sendfile(filePath, { maxAge: exports.maxAge });
}); });
//serve timeslider.html under /p/$padname/timeslider //serve timeslider.html under /$padname/timeslider or /p/$padname/timeslider
app.get('/p/:pad/timeslider', function(req, res, next) app.get('(/p)?/:pad/timeslider', function(req, res, next)
{ {
var filePath = path.normalize(__dirname + "/../static/timeslider.html"); var filePath = path.normalize(__dirname + "/../static/timeslider.html");
res.sendfile(filePath, { maxAge: exports.maxAge }); res.sendfile(filePath, { maxAge: exports.maxAge });
}); });
//serve timeslider.html under /p/$padname/timeslider //handle export requests
app.get('/p/:pad/:rev?/export/:type', function(req, res, next) app.get('/:pad/:rev?/export/:type', function(req, res, next)
{ {
var types = ["pdf", "doc", "txt", "html", "odt", "dokuwiki"]; var types = ["pdf", "doc", "txt", "html", "odt", "dokuwiki"];
//send a 404 if we don't support this filetype //send a 404 if we don't support this filetype
@ -296,7 +335,8 @@ async.waterfall([
}); });
//handle import requests //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 abiword is disabled, skip handling this request
if(settings.abiword == null) 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 //let the server listen
app.listen(settings.port, settings.ip); app.listen(settings.port, settings.ip);
console.log("Server is listening at " + settings.ip + ":" + settings.port); console.log("Server is listening at " + settings.ip + ":" + settings.port);

View file

@ -240,9 +240,9 @@ var padimpexp = (function()
{ {
pad = _pad; pad = _pad;
//get /p/padname //get /p/padname or /padname
var pad_root_path = new RegExp(/.*\/p\/[^\/]+/).exec(document.location.pathname) var pad_root_path = new RegExp(/.*\/[^\/]+/).exec(document.location.pathname)
//get http://example.com/p/padname //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) var pad_root_url = document.location.href.replace(document.location.pathname, pad_root_path)
// build the export links // build the export links