mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
move 'static' routes into own module
This commit is contained in:
parent
38354f6ae5
commit
b8c0bb2ea2
2 changed files with 59 additions and 48 deletions
55
node/routes/static.js
Normal file
55
node/routes/static.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
var path = require('path');
|
||||
|
||||
module.exports = function(app)
|
||||
{
|
||||
|
||||
app.get('/static/*', function(req, res)
|
||||
{
|
||||
var filePath = path.normalize(__dirname + "/../.." +
|
||||
req.url.replace(/\.\./g, '').split("?")[0]);
|
||||
res.sendfile(filePath, { maxAge: app.maxAge });
|
||||
});
|
||||
|
||||
//serve pad.html under /p
|
||||
app.get('/p/:pad', function(req, res, next)
|
||||
{
|
||||
var filePath = path.normalize(__dirname + "/../../static/pad.html");
|
||||
res.sendfile(filePath, { maxAge: app.maxAge });
|
||||
});
|
||||
|
||||
//serve timeslider.html under /p/$padname/timeslider
|
||||
app.get('/p/:pad/timeslider', function(req, res, next)
|
||||
{
|
||||
var filePath = path.normalize(__dirname + "/../../static/timeslider.html");
|
||||
res.sendfile(filePath, { maxAge: app.maxAge });
|
||||
});
|
||||
|
||||
//serve index.html under /
|
||||
app.get('/', function(req, res)
|
||||
{
|
||||
var filePath = path.normalize(__dirname + "/../../static/index.html");
|
||||
res.sendfile(filePath, { maxAge: app.maxAge });
|
||||
});
|
||||
|
||||
//serve robots.txt
|
||||
app.get('/robots.txt', function(req, res)
|
||||
{
|
||||
var filePath = path.normalize(__dirname + "/../../static/robots.txt");
|
||||
res.sendfile(filePath, { maxAge: app.maxAge });
|
||||
});
|
||||
|
||||
//serve favicon.ico
|
||||
app.get('/favicon.ico', function(req, res)
|
||||
{
|
||||
var filePath = path.normalize(__dirname + "/../../static/custom/favicon.ico");
|
||||
res.sendfile(filePath, { maxAge: app.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: app.maxAge });
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
|
@ -79,6 +79,8 @@ async.waterfall([
|
|||
//create server
|
||||
var app = express.createServer();
|
||||
|
||||
app.maxAge = exports.maxAge;
|
||||
|
||||
app.use(function (req, res, next) {
|
||||
res.header("Server", serverName);
|
||||
next();
|
||||
|
@ -147,12 +149,6 @@ async.waterfall([
|
|||
res.write(minify.requireDefinition());
|
||||
res.end();
|
||||
});
|
||||
app.get('/static/*', function(req, res)
|
||||
{
|
||||
var filePath = path.normalize(__dirname + "/.." +
|
||||
req.url.replace(/\.\./g, '').split("?")[0]);
|
||||
res.sendfile(filePath, { maxAge: exports.maxAge });
|
||||
});
|
||||
|
||||
//serve minified files
|
||||
app.get('/minified/:filename', minify.minifyJS);
|
||||
|
@ -254,19 +250,6 @@ async.waterfall([
|
|||
});
|
||||
});
|
||||
|
||||
//serve pad.html under /p
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
@ -355,35 +338,8 @@ async.waterfall([
|
|||
|
||||
require('./routes/debug')(app);
|
||||
|
||||
//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 });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
require('./routes/static')(app);
|
||||
|
||||
//let the server listen
|
||||
app.listen(settings.port, settings.ip);
|
||||
console.log("Server is listening at " + settings.ip + ":" + settings.port);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue