summaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorWu Cheng-Han2016-12-12 10:50:43 +0800
committerWu Cheng-Han2016-12-12 10:50:43 +0800
commit38505491ae9f9652249010c012ba36cc7b64f753 (patch)
tree0403e53a7a5adc4856747c29fa9b29d58ec220c7 /app.js
parent46752194e45e09ac75fe0ab20f856aa6e1379c3d (diff)
Fix redirection to url without trailing slashes not considering about config urlpath
Diffstat (limited to 'app.js')
-rw-r--r--app.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/app.js b/app.js
index 776ad8d0..77469f14 100644
--- a/app.js
+++ b/app.js
@@ -182,11 +182,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();
}