Skip to content

Commit

Permalink
Optionally strip off the basename from the dashboard URL when
Browse files Browse the repository at this point in the history
normalizing.
  • Loading branch information
ian-r-rose committed Dec 11, 2018
1 parent 247c004 commit f4464cd
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IFrame, MainAreaWidget, ToolbarButton } from '@jupyterlab/apputils';

import { URLExt } from '@jupyterlab/coreutils';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';

import { ServerConnection } from '@jupyterlab/services';

Expand Down Expand Up @@ -453,12 +453,25 @@ namespace Private {
/**
* Optionally remove a `status` route from a dashboard url.
*/
export function normalizeDashboardUrl(url: string): string {
if (url.endsWith('status')) {
return url.slice(0, -'status'.length);
export function normalizeDashboardUrl(url: string, baseUrl = ''): string {
if (URLExt.isLocal(url)) {
if (!baseUrl) {
baseUrl = PageConfig.getBaseUrl();
}
// If the path-portion of the baseUrl has been included,
// strip that off.
const tmp = new URL(baseUrl);
if (url.startsWith(tmp.pathname)) {
url = url.slice(tmp.pathname.length);
}
// Fully specify the local URL.
url = URLExt.join(baseUrl, url);
}
if (url.endsWith('status/')) {
return url.slice(0, -'status/'.length);
// If 'status' has been included at the end, strip it.
if (url.endsWith('status')) {
url = url.slice(0, -'status'.length);
} else if (url.endsWith('status/')) {
url = url.slice(0, -'status/'.length);
}
return url;
}
Expand All @@ -470,7 +483,7 @@ namespace Private {
url: string,
settings: ServerConnection.ISettings
): Promise<boolean> {
url = normalizeDashboardUrl(url);
url = normalizeDashboardUrl(url, settings.baseUrl);

// If this is a url that we are proxying under the notebook server,
// it is easier to check for a valid dashboard.
Expand Down

0 comments on commit f4464cd

Please sign in to comment.