Improve root api endpoint finding

The relative paths here weren't really doing their job. Instead, go
ahead and pull in the function we wrote for the later angular5 patch to
dynamically find the base href and use it to figure out what we should
be appending the api paths to.

Also, Remove double api prefix from tenants call

Erroneously added it in the previous patch while also updating
getSourceUrl to pre-pend the api string appropriately.

Change-Id: Ib58c4569dbe21824c138c57c6353454ea1e4bc71
This commit is contained in:
Monty Taylor 2018-03-28 11:30:05 -05:00
parent 1243cf75f4
commit bcfc82b6a9
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 18 additions and 9 deletions

View File

@ -29,7 +29,7 @@ angular.module('zuulTenants', []).controller(
'mainController', function ($scope, $http, $location) {
$scope.tenants = undefined
$scope.tenants_fetch = function () {
$http.get(getSourceUrl('api/tenants', $location))
$http.get(getSourceUrl('tenants', $location))
.then(function success (result) {
$scope.tenants = result.data
})

View File

@ -1,4 +1,4 @@
/* global ZUUL_API_URL */
/* global URL, ZUUL_API_URL */
// @licstart The following is the entire license notice for the
// JavaScript code in this page.
//
@ -37,15 +37,24 @@ export function getSourceUrl (filename, $location) {
if (typeof ZUUL_API_URL !== 'undefined') {
return `${ZUUL_API_URL}/api/${filename}`
} else {
let tenant = extractTenant($location.url())
const currentUrl = new URL(window.location)
const tenant = extractTenant(currentUrl.href)
const baseHref = getBaseHrefFromPath(currentUrl.pathname)
if (tenant) {
// Multi-tenant deploy. This is at t/a-tenant/x.html. api path is at
// api/tenant/a-tenant/x, so should be at ../../api/tenant/a-tenant/x
return `../../api/tenant/${tenant}/${filename}`
// Multi-tenant deploy. This is at t/a-tenant/x.html
return `${baseHref}api/tenant/${tenant}/${filename}`
} else {
// Whilelabel deploy. This is at x.html. api path is at
// api/x, so should be at api/x
return `api/${filename}`
// Whitelabel deploy or tenants list, such as /status.html, /tenants.html
// or /zuul/status.html or /zuul/tenants.html
return `${baseHref}api/${filename}`
}
}
}
function getBaseHrefFromPath (path) {
if (path.includes('/t/')) {
return path.slice(0, path.lastIndexOf('/t/') + 1)
} else {
return path.split('/').slice(0, -1).join('/') + '/'
}
}