Skip to content

Commit c6434f6

Browse files
authored
Fix handling of hubHost (#501)
hubHost is either an empty string or full proto://hostname[:port], not a hostname hub api url should prepend hubHost as-is, so it is either an absolute path (most cases) or a full URL.
1 parent 889ca75 commit c6434f6

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

packages/collaboration/src/sharedlink.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ export async function showSharedLinkDialog({
134134
serverOwner = PageConfig.getOption('hubServerUser');
135135
serverName = PageConfig.getOption('hubServerName');
136136
// Prepare the Hub API URL
137-
const protocol = window.location.protocol;
138-
const hostname =
139-
PageConfig.getOption('hubHost') || window.location.hostname;
140-
const port = window.location.port;
137+
// hubHost is the full Origin (`proto://hostname:port`)
138+
// or an empty string, making hubApiUrl an absolute path on the current origin
139+
const hubHost = PageConfig.getOption('hubHost') || '';
141140
const prefix = PageConfig.getOption('hubPrefix');
142-
hubApiUrl = `${protocol}//${hostname}:${port}${prefix}api`;
141+
hubApiUrl = `${hubHost}${prefix}api`;
143142
// Check Hub version for share compatibility (>= 5.0)
144143
const response = await fetch(hubApiUrl, {
145144
// A GET request on base API url returns the Hub version

ui-tests/tests/hub-share.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('should open JupyterHub sharing dialog', async ({ page }) => {
1515
document.body.dataset['hubUser'] = 'jovyan';
1616
document.body.dataset['hubServerUser'] = 'jovyan';
1717
document.body.dataset['hubServerName'] = 'my-server';
18-
document.body.dataset['hubHost'] = 'localhost';
18+
document.body.dataset['hubHost'] = '';
1919
document.body.dataset['hubPrefix'] = '/hub/';
2020
});
2121

0 commit comments

Comments
 (0)