diff options
Diffstat (limited to 'app.js')
-rw-r--r-- | app.js | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -11,6 +11,7 @@ var compression = require('compression') var session = require('express-session'); var SequelizeStore = require('connect-session-sequelize')(session.Store); var fs = require('fs'); +var path = require('path'); var imgur = require('imgur'); var formidable = require('formidable'); var morgan = require('morgan'); @@ -182,11 +183,14 @@ app.use(function(req, res, next) { next(); }); -// redirect url with trailing slashes +// redirect url without trailing slashes app.use(function(req, res, next) { if ("GET" == req.method && req.path.substr(-1) == '/' && req.path.length > 1) { var query = req.url.slice(req.path.length); - res.redirect(301, config.serverurl + req.path.slice(0, -1) + query); + var urlpath = req.path.slice(0, -1); + var serverurl = config.serverurl; + if (config.urlpath) serverurl = serverurl.slice(0, -(config.urlpath.length + 1)); + res.redirect(301, serverurl + urlpath + query); } else { next(); } |