Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explorer: Fix issue with domains in hosted envs #2734

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions explorer/src/lib/url/makeNodeUrl.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
/**
* Constructs a node URL based on the current subdomain
*
* @param {string} path
* @returns {URL} nodeUrl
*/
function makeNodeUrl(path = "") {
const domains = window.location.hostname.split(".");
if (path && !path.startsWith("/")) {
throw new Error("A path must start with a '/'.");
}

const subDomains = window.location.hostname.split(".");
const hostedNodeDomain = subDomains.slice(1).join(".");
const nodeBaseUrl = import.meta.env.VITE_NODE_URL || "";
const nodeBasePath = import.meta.env.VITE_RUSK_PATH || "";

/**
* @param {string} base
* @returns {URL}
*/
const buildHostedNodeUrl = (base) =>
new URL(
`${window.location.protocol}${base}${hostedNodeDomain}${nodeBasePath}${path}`
);

let node;

switch (domains[0]) {
switch (subDomains[0]) {
case "apps": // mainnet
node = new URL(
`${window.location.protocol}nodes.${window.location.host}${path}`
);
node = buildHostedNodeUrl("nodes.");
break;
case "devnet":
node = new URL(
`${window.location.protocol}devnet.nodes.${window.location.host}${path}`
);
node = buildHostedNodeUrl("devnet.nodes.");
break;
case "testnet":
node = new URL(
`${window.location.protocol}testnet.nodes.${window.location.host}${path}`
);
node = buildHostedNodeUrl("testnet.nodes.");
break;
default: // localnet
if (import.meta.env.VITE_NODE_URL) {
node = new URL(
`${import.meta.env.VITE_NODE_URL}${path}`,
import.meta.url
);
} else {
node = new URL(
`${import.meta.env.VITE_RUSK_PATH || "/"}${path}`,
import.meta.url
);
}

default:
node = new URL(`${nodeBaseUrl}${nodeBasePath}${path}`, import.meta.url);
break;
}

Expand Down
Loading