Skip to content

Commit

Permalink
fix: fix regex API prefix substitution for dataset selection (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
atarashansky authored Mar 4, 2024
1 parent b7d377b commit bd4f07a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
<script type="text/javascript">
window.CELLXGENE = {};
window.CELLXGENE.API = {
prefix: `http://localhost:<%= CXG_SERVER_PORT %>${location.pathname}/api/`,
// When there's a trailing slash on location.pathname, local e2e tests fail because
// they attempt to access http://localhost:3000//pbmc3k.cxg/api/ instead of
// http://localhost:3000/pbmc3k.cxg/api/. This is a workaround for that issue.
prefix: `http://localhost:<%= CXG_SERVER_PORT %>${location.pathname.replace(/\/$/, "")}/api/`,
version: "v0.3/",
};
</script>
Expand Down
14 changes: 13 additions & 1 deletion client/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export const QUERY_PARAM_EXPLAIN_NEW_TAB = "explainNewTab";
*/
const REGEX_PATHNAME = /(?<=\/)[^/]{1}\/(?:[^/]+\/)*[^/]+\/(?=api)/;

/**
* This regex is used to update the API prefix when the dataset selector is used.
* It matches the previous two segments (demarcated by `/`) leading up to `/api`.
* In deployed environments, these segments will be `s3_uri` and the S3 URI of the dataset.
* We require a separate REGEX because the dataset selector is applied to an API prefix that
* has already been updated with the S3 URI of the dataset.
*/
const REGEX_PATHNAME_FOR_DATASET_SELECTOR = /(?<=\/)\w+\/[^/]+\/(?=api)/;

/* Config links types */
export type ConfigLink = "about-dataset" | "collections-home-page";

Expand Down Expand Up @@ -201,7 +210,10 @@ export function updateApiPrefix(): void {
const pathname = location.pathname.substring(1);
// For the API prefix in the format protocol/host/pathSegement/e/uuid.cxg, replace /e/uuid.cxg with the corresponding
// path segments taken from the pathname.
API.prefix = API.prefix.replace(REGEX_PATHNAME, pathname);
API.prefix = API.prefix.replace(
REGEX_PATHNAME_FOR_DATASET_SELECTOR,
pathname
);
}

/**
Expand Down

0 comments on commit bd4f07a

Please sign in to comment.