From b8042c722e1d706df5b928a6fcaf4d35bf9c05b6 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Wed, 11 Jul 2018 10:44:37 +0100 Subject: [PATCH] Instead of rewriting the API call, use ember to rewrite the URL We now essentially do 2 redirects if you hit a `folder/` 1. If you visit `/ui/dc1/kv/folder/`, `consul` will redirect you to `/ui/dc1/kv/folder` 2. Once redirected to `/ui/dc1/kv/folder` via a 301, use ember/history API to redirect you back to `/ui/dc1/kv/folder/`. Bit long winded, but achieves what we want without having to get stuck into `consul` itself to remove the 301 for the UI --- ui-v2/app/routes/dc/kv/index.js | 10 +++++++--- ui-v2/tests/acceptance/dc/kvs/trailing-slash.feature | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ui-v2/app/routes/dc/kv/index.js b/ui-v2/app/routes/dc/kv/index.js index 9f1f3007b..5d32c5df6 100644 --- a/ui-v2/app/routes/dc/kv/index.js +++ b/ui-v2/app/routes/dc/kv/index.js @@ -13,13 +13,17 @@ export default Route.extend(WithKvActions, { }, }, repo: service('kv'), - model: function(params) { - let key = params.key || '/'; + beforeModel: function() { // we are index or folder, so if the key doesn't have a trailing slash // add one to force a fake findBySlug + const params = this.paramsFor(this.routeName); + const key = params.key || '/'; if (!isFolder(key)) { - key = key + '/'; + return this.replaceWith(this.routeName, key + '/'); } + }, + model: function(params) { + let key = params.key || '/'; const dc = this.modelFor('dc').dc.Name; const repo = get(this, 'repo'); return hash({ diff --git a/ui-v2/tests/acceptance/dc/kvs/trailing-slash.feature b/ui-v2/tests/acceptance/dc/kvs/trailing-slash.feature index 9a999f2d8..9921a0353 100644 --- a/ui-v2/tests/acceptance/dc/kvs/trailing-slash.feature +++ b/ui-v2/tests/acceptance/dc/kvs/trailing-slash.feature @@ -8,7 +8,7 @@ Feature: dc / kvs / trailing slash dc: datacenter kv: foo/bar --- - Then the url should be /datacenter/kv/foo/bar + Then the url should be /datacenter/kv/foo/bar/ And the last GET request was made to "/v1/kv/foo/bar/?keys&dc=datacenter&separator=%2F" When I visit the kvs page for yaml ---