move / redirection to catch-all route so that routes can use trailing slashes

This commit is contained in:
Spencer Alger 2015-06-30 08:10:25 -07:00
parent f51ec29837
commit 615f4c972a

View file

@ -9,19 +9,6 @@ module.exports = function (kbnServer, server, config) {
port: config.get('kibana.server.port')
});
server.ext('onRequest', function (req, reply) {
var path = req.path;
if (path === '/' || path.charAt(path.length - 1) !== '/') {
return reply.continue();
}
return reply.redirect(format({
search: req.url.search,
pathname: path.slice(0, -1),
}))
.permanent(true);
});
// provide a simple way to expose static directories
server.decorate('server', 'exposeStaticDir', function (routePath, dirPath) {
this.route({
@ -70,4 +57,21 @@ module.exports = function (kbnServer, server, config) {
reply.redirect(config.get('kibana.defaultRoute'));
}
});
server.route({
method: 'GET',
path: '/{p*}',
handler: function (req, reply) {
var path = req.path;
if (path === '/' || path.charAt(path.length - 1) !== '/') {
return reply(Boom.notFound());
}
return reply.redirect(format({
search: req.url.search,
pathname: path.slice(0, -1),
}))
.permanent(true);
}
});
};