Skip to content

Commit b5c1c38

Browse files
committed
Move redirect calculation to Spec object
1 parent 23e491e commit b5c1c38

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

binderhub/static/js/components/BuilderLauncher.jsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ import "xterm/css/xterm.css";
66
import { Progress, PROGRESS_STATES } from "./Progress.jsx";
77
import { Spec } from "../spec.js";
88

9-
/**
10-
*
11-
* @param {string} serverUrl
12-
* @param {string} token
13-
* @param {string} urlPath
14-
*/
15-
function redirectToRunningServer(serverUrl, token, urlPath) {
16-
const redirectUrl = new URL(urlPath, serverUrl);
17-
redirectUrl.searchParams.append("token", token);
18-
window.location.href = redirectUrl.toString();
19-
}
20-
219
/**
2210
*
2311
* @param {URL} baseUrl
@@ -64,7 +52,11 @@ async function buildImage(
6452
case "ready": {
6553
setProgressState(PROGRESS_STATES.SUCCESS);
6654
image.close();
67-
redirectToRunningServer(data.url, data.token, spec.launchSpec.urlPath);
55+
const serverUrl = new URL(data.url);
56+
window.location.href = spec.launchSpec.getJupyterServerRedirectUrl(
57+
serverUrl,
58+
data.token,
59+
);
6860
console.log(data);
6961
break;
7062
}

binderhub/static/js/spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ export class LaunchSpec {
99
this.urlPath = this.urlPath.replace(/^\/*/, "");
1010
}
1111

12+
/**
13+
* Return a URL to redirect user to for use with this launch specification
14+
*
15+
* @param {URL} serverUrl Fully qualified URL to a running Jupyter Server
16+
* @param {string} token Authentication token to pass to the Jupyter Server
17+
*
18+
* @returns {URL}
19+
*/
20+
getJupyterServerRedirectUrl(serverUrl, token) {
21+
const redirectUrl = new URL(this.urlPath, serverUrl);
22+
redirectUrl.searchParams.append("token", token);
23+
return redirectUrl;
24+
}
25+
1226
/**
1327
* Create a LaunchSpec from given query parameters in the URL
1428
*

0 commit comments

Comments
 (0)