diff --git a/web/dashboard.js b/web/dashboard.js index 409d2bdf26..77884e5b50 100644 --- a/web/dashboard.js +++ b/web/dashboard.js @@ -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 }) diff --git a/web/util.js b/web/util.js index b8a418650d..89cff40df9 100644 --- a/web/util.js +++ b/web/util.js @@ -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('/') + '/' + } +}