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
This commit is contained in:
John Cowen 2018-07-11 10:44:37 +01:00
parent 946bdd6d6e
commit b8042c722e
2 changed files with 8 additions and 4 deletions

View File

@ -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({

View File

@ -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
---