Explorer: Disable cluster url replacement on localhost (#28385)

This commit is contained in:
Justin Starry 2022-10-14 09:38:39 +08:00 committed by GitHub
parent dd7fee8f32
commit f627b7d826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -61,13 +61,21 @@ export const TESTNET_URL = clusterApiUrl("testnet");
export const DEVNET_URL = clusterApiUrl("devnet"); export const DEVNET_URL = clusterApiUrl("devnet");
export function clusterUrl(cluster: Cluster, customUrl: string): string { export function clusterUrl(cluster: Cluster, customUrl: string): string {
const modifyUrl = (url: string): string => {
if (window.location.hostname === "localhost") {
return url;
} else {
return url.replace("api", "explorer-api");
}
};
switch (cluster) { switch (cluster) {
case Cluster.Devnet: case Cluster.Devnet:
return DEVNET_URL.replace("api", "explorer-api"); return modifyUrl(DEVNET_URL);
case Cluster.MainnetBeta: case Cluster.MainnetBeta:
return MAINNET_BETA_URL.replace("api", "explorer-api"); return modifyUrl(MAINNET_BETA_URL);
case Cluster.Testnet: case Cluster.Testnet:
return TESTNET_URL.replace("api", "explorer-api"); return modifyUrl(TESTNET_URL);
case Cluster.Custom: case Cluster.Custom:
return customUrl; return customUrl;
} }