From ecc5f5ed6309f5bf4df2d7b022b12e8a3ea4e55e Mon Sep 17 00:00:00 2001 From: Filip Barl Date: Mon, 11 Jun 2018 15:56:28 +0200 Subject: [PATCH] Separate API endpoint namespace from URL path part. --- client/app/scripts/utils/web-api-utils.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/app/scripts/utils/web-api-utils.js b/client/app/scripts/utils/web-api-utils.js index 8d243a836..1c945f9ca 100644 --- a/client/app/scripts/utils/web-api-utils.js +++ b/client/app/scripts/utils/web-api-utils.js @@ -87,11 +87,13 @@ export function basePathSlash(urlPath) { return `${basePath(urlPath)}/`; } +// TODO: This helper should probably be passed by the 'user' of Scope, +// i.e. in this case Weave Cloud, rather than being hardcoded here. export function getApiPath(pathname = window.location.pathname) { if (process.env.SCOPE_API_PREFIX) { - // Flip the current namespaces and instanceName args to match Weave Cloud routes. - const [, instanceName, namespace] = pathname.split('/'); - return basePath(`${process.env.SCOPE_API_PREFIX}/${namespace}/${instanceName}`); + // Extract the instance name (pathname in WC context is of format '/:orgId/explore'). + const orgId = pathname.split('/')[1]; + return basePath(`${process.env.SCOPE_API_PREFIX}/app/${orgId}`); } return basePath(pathname);