mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Preserve querystring when ensuring path ends with slash
This commit is contained in:
parent
def93214de
commit
266a644ca6
@ -31,8 +31,11 @@ events.on("node-icon-dir",function(dir) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ensureSlash: function(req,res,next) {
|
ensureSlash: function(req,res,next) {
|
||||||
if (req.originalUrl.slice(-1) != "/") {
|
var parts = req.originalUrl.split("?");
|
||||||
res.redirect(301,req.originalUrl+"/");
|
if (parts[0].slice(-1) != "/") {
|
||||||
|
parts[0] += "/";
|
||||||
|
var redirect = parts.join("?");
|
||||||
|
res.redirect(301,redirect);
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,19 @@ describe("ui api", function() {
|
|||||||
.get('/foo')
|
.get('/foo')
|
||||||
.expect(301,done);
|
.expect(301,done);
|
||||||
});
|
});
|
||||||
|
it('redirects if the path, with query string, does not end in a slash',function(done) {
|
||||||
|
request(app)
|
||||||
|
.get('/foo?abc=def')
|
||||||
|
.expect(301)
|
||||||
|
.end(function(err,res) {
|
||||||
|
if (err) {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
res.header['location'].should.equal("/foo/?abc=def");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('does not redirect if the path ends in a slash',function(done) {
|
it('does not redirect if the path ends in a slash',function(done) {
|
||||||
request(app)
|
request(app)
|
||||||
.get('/foo/')
|
.get('/foo/')
|
||||||
|
Loading…
Reference in New Issue
Block a user