Skip to content

Commit

Permalink
referenced the raw request when setting next
Browse files Browse the repository at this point in the history
resolves #150
  • Loading branch information
travi committed Feb 9, 2018
1 parent 22dfeb1 commit 006f935
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -210,7 +210,7 @@ internals.implementation = function (server, options) {
uri += '?';
}

uri += settings.appendNext + '=' + encodeURIComponent(request.url.path);
uri += settings.appendNext + '=' + encodeURIComponent(request.raw.req.url);
}

return reply('You are being redirected...', null, result).redirect(uri);
Expand Down
39 changes: 39 additions & 0 deletions test/index.js
Expand Up @@ -1569,6 +1569,45 @@ describe('scheme', () => {
});
});

it('retains the original path when onRequest re-routes', (done) => {

const server = new Hapi.Server();
server.connection();
server.register(require('../'), (err) => {

expect(err).to.not.exist();

server.auth.strategy('default', 'cookie', true, {
password: 'password-should-be-32-characters',
ttl: 60 * 1000,
redirectTo: 'http://example.com/login?mode=1',
appendNext: true
});

server.route({
method: 'GET', path: '/', handler: function (request, reply) {

return reply('never');
}
});

server.ext('onRequest', (request, reply) => {

request.setUrl('/');

reply.continue();
});

server.inject('/foo?bar=baz', (res) => {

expect(res.statusCode).to.equal(302);
expect(res.headers.location).to.equal('http://example.com/login?mode=1&next=%2Ffoo%3Fbar%3Dbaz');
done();
});
});
});


it('appends the custom query when appendNext is string', (done) => {

const server = new Hapi.Server();
Expand Down

0 comments on commit 006f935

Please sign in to comment.