Separate API endpoint namespace from URL path part.

This commit is contained in:
Filip Barl
2018-06-11 15:56:28 +02:00
parent 8c18a785e7
commit ecc5f5ed63

View File

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