diff --git a/binderhub/static/js/index.js b/binderhub/static/js/index.js index 7630b0d33..536a4e278 100644 --- a/binderhub/static/js/index.js +++ b/binderhub/static/js/index.js @@ -18,10 +18,32 @@ import "bootstrap/dist/css/bootstrap-theme.min.css"; import "../index.css"; import { setUpLog } from "./src/log"; import { updateUrls } from "./src/urls"; -import { BASE_URL, BADGE_BASE_URL } from "./src/constants"; import { getBuildFormValues } from "./src/form"; import { updateRepoText } from "./src/repo"; +/** + * @type {URL} + * Base URL of this binderhub installation. + * + * Guaranteed to have a leading & trailing slash by the binderhub python configuration. + */ +const BASE_URL = new URL( + document.getElementById("base-url").dataset.url, + document.location.origin, +); + +const badge_base_url = document.getElementById("badge-base-url").dataset.url; +/** + * @type {URL} + * Base URL to use for both badge images as well as launch links. + * + * If not explicitly set, will default to BASE_URL. Primarily set up different than BASE_URL + * when used as part of a federation + */ +const BADGE_BASE_URL = badge_base_url + ? new URL(badge_base_url, document.location.origin) + : BASE_URL; + async function build(providerSpec, log, fitAddon, path, pathType) { updateFavicon(new URL("favicon_building.ico", BASE_URL)); // split provider prefix off of providerSpec @@ -128,7 +150,7 @@ function indexMain() { $("#provider_prefix-selected").text($(this).text()); $("#provider_prefix").val($(this).attr("value")); - updateRepoText(); + updateRepoText(BASE_URL); updateUrls(BADGE_BASE_URL); }); @@ -142,7 +164,7 @@ function indexMain() { updateUrls(BADGE_BASE_URL); }); updatePathText(); - updateRepoText(); + updateRepoText(BASE_URL); $("#repository").on("keyup paste change", function () { updateUrls(BADGE_BASE_URL); diff --git a/binderhub/static/js/src/constants.js b/binderhub/static/js/src/constants.js deleted file mode 100644 index 3057e1681..000000000 --- a/binderhub/static/js/src/constants.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @type {URL} - * Base URL of this binderhub installation. - * - * Guaranteed to have a leading & trailing slash by the binderhub python configuration. - */ -export const BASE_URL = new URL( - document.getElementById("base-url").dataset.url, - document.location.origin, -); - -const badge_base_url = document.getElementById("badge-base-url").dataset.url; -/** - * @type {URL} - * Base URL to use for both badge images as well as launch links. - * - * If not explicitly set, will default to BASE_URL. Primarily set up different than BASE_URL - * when used as part of a federation. - * - * Guaranteed to have a trailing slash by the binderhub python configuration. - */ -export const BADGE_BASE_URL = badge_base_url - ? new URL(badge_base_url, document.location.origin) - : BASE_URL; diff --git a/binderhub/static/js/src/repo.js b/binderhub/static/js/src/repo.js index 4cbcf1b1a..e848b49ed 100644 --- a/binderhub/static/js/src/repo.js +++ b/binderhub/static/js/src/repo.js @@ -1,5 +1,3 @@ -import { BASE_URL } from "./constants"; - /** * Dict holding cached values of API request to _config endpoint */ @@ -21,10 +19,12 @@ function setLabels() { /** * Update labels for various inputboxes based on user selection of repo provider + * + * @param {URL} baseUrl Base URL to use for constructing path to _config endpoint */ -export function updateRepoText() { +export function updateRepoText(baseUrl) { if (Object.keys(configDict).length === 0) { - const configUrl = new URL("_config", BASE_URL); + const configUrl = new URL("_config", baseUrl); fetch(configUrl).then((resp) => { resp.json().then((data) => { configDict = data;