Skip to content

Commit

Permalink
Move redirect calculation to Spec object
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed May 24, 2024
1 parent ff7645d commit c6eaef5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
18 changes: 5 additions & 13 deletions binderhub/static/js/components/BuilderLauncher.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ import "xterm/css/xterm.css";
import { Progress, PROGRESS_STATES } from "./Progress.jsx";
import { Spec } from "../spec.js";

/**
*
* @param {string} serverUrl
* @param {string} token
* @param {string} urlPath
*/
function redirectToRunningServer(serverUrl, token, urlPath) {
const redirectUrl = new URL(urlPath, serverUrl);
redirectUrl.searchParams.append("token", token);
window.location.href = redirectUrl.toString();
}

/**
*
* @param {URL} baseUrl
Expand Down Expand Up @@ -64,7 +52,11 @@ async function buildImage(
case "ready": {
setProgressState(PROGRESS_STATES.SUCCESS);
image.close();
redirectToRunningServer(data.url, data.token, spec.launchSpec.urlPath);
const serverUrl = new URL(data.url);
window.location.href = spec.launchSpec.getJupyterServerRedirectUrl(
serverUrl,
data.token,
);
console.log(data);
break;
}
Expand Down
14 changes: 14 additions & 0 deletions binderhub/static/js/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ export class LaunchSpec {
this.urlPath = this.urlPath.replace(/^\/*/, "");
}

/**
* Return a URL to redirect user to for use with this launch specification
*
* @param {URL} serverUrl Fully qualified URL to a running Jupyter Server
* @param {string} token Authentication token to pass to the Jupyter Server
*
* @returns {URL}
*/
getJupyterServerRedirectUrl(serverUrl, token) {
const redirectUrl = new URL(this.urlPath, serverUrl);
redirectUrl.searchParams.append("token", token);
return redirectUrl;
}

/**
* Create a LaunchSpec from given query parameters in the URL
*
Expand Down

0 comments on commit c6eaef5

Please sign in to comment.