-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JS: Refactor link & badge generation, use URLs (not string) for base …
…URLs This is two changes that were easier to make together - BASE_URL and BADGE_BASE_URL are now URL objects rather than strings that are manipulated. With this done, we no longer use string manipulation for URLs anywhere! - Both BASE_URL and BADGE_BASE_URL are now always set, as we had a bunch of code that was using BADGE_BASE_URL if available but falls back to BASE_URL + origin if it was not set. This fallback is now implemented globally, and correctly. - BASE_URL is also now always fully qualified, and we document that the python code ensures it has a trailing slash always. - The function to make links and generate badge markup is moved into `@jupyterhub/binderhub-client` as it is reasonably generic and not super specific to our frontend alone. This also involves them not reading BASE_URL and BADGE_BASE_URL globally, but having that information be passed in. Tests are also added here to catch any future issues that may arise. - Note for future fix - BADGE_BASE_URL is really PUBLIC_BASE_URL or similar, as it is used both for the location of the badge image (original intent) but also for the links we generate to share. This is relevant only for federation, where we want shared links to point to mybinder.org even though the API call itself may go to a specific member of the federation. I will do this deprecation + rename in a future PR so as to not make this PR bigger. Ref #774
- Loading branch information
Showing
8 changed files
with
204 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
/** | ||
* @type {string} | ||
* Base URL of this binderhub installation | ||
* @type {URL} | ||
* Base URL of this binderhub installation. | ||
* | ||
* Guaranteed to have a trailing slash by the binderhub python configuration. | ||
*/ | ||
export const BASE_URL = $("#base-url").data().url; | ||
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 {string} | ||
* Optional base URL to use for both badge images as well as launch links. | ||
* @type {URL} | ||
* Base URL to use for both badge images as well as launch links. | ||
* | ||
* Is different from BASE_URL primarily when used as part of a federation. | ||
* If not explicitly set, will default to BASE_URL. Primarily set up different than BASE_URL | ||
* when used as part of a federation | ||
*/ | ||
export const BADGE_BASE_URL = $("#badge-base-url").data().url; | ||
export const BADGE_BASE_URL = badge_base_url | ||
? new URL(badge_base_url, document.location.origin) | ||
: BASE_URL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.