@@ -161,48 +161,61 @@ def get_uid_str(uid):
161161const { createRoot } = await importWithMap("react-dom/client", importMap);
162162
163163const e = React.createElement;
164-
164+ const WORKSPACES_URL_KEYWORD = 'https://workspaces-pt'
165165const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
166-
167166// The jupyter server may be running through a proxy,
168167// which means that the client needs to prepend the part of the URL before /proxy/8000 such as
169168// https://hub.gke2.mybinder.org/user/vitessce-vitessce-python-swi31vcv/proxy/8000/A/0/cells
169+ // For workspaces: https://workspaces-pt.hubmapconsortium.org/passthrough/HOSTNAME/PORT/ADDITIONAL_PATH_INFO?QUERY_PARAMS=HELLO_WORLD
170170function prependBaseUrl(config, proxy, hasHostName) {
171- if (!proxy || hasHostName) {
171+ if (!proxy || hasHostName) {
172172 return config;
173- }
174- const { origin } = new URL(window.location.href);
175- const pathSegments = window.location.pathname.split('/');
176- let baseUrl;
177- const passthroughIndex = pathSegments.indexOf('passthrough');
178- if (passthroughIndex !== -1) {
179- baseUrl = pathSegments.slice(0, passthroughIndex + 3).join('/');
180- } else {
173+ }
174+ let proxyPath;
175+ const { origin } = new URL(window.location.href);
176+ const isInWorkspaces = origin.includes(WORKSPACES_URL_KEYWORD)
177+ if (isInWorkspaces) {
178+ const pathSegments = window.location.pathname.split('/');
179+ const passthroughIndex = pathSegments.indexOf('passthrough');
180+ if (passthroughIndex !== -1) {
181+ proxyPath = pathSegments.slice(0, passthroughIndex + 3).join('/');
182+ }
183+ }
181184 const jupyterLabConfigEl = document.getElementById('jupyter-config-data');
182-
185+ let baseUrl;
183186 if (jupyterLabConfigEl) {
184187 // This is jupyter lab
185188 baseUrl = JSON.parse(jupyterLabConfigEl.textContent || '').baseUrl;
186189 } else {
187190 // This is jupyter notebook
188191 baseUrl = document.getElementsByTagName('body')[0].getAttribute('data-base-url');
189- }
190- }
191-
192- // Ensure baseUrl starts with a slash
193- if (!baseUrl.startsWith('/')) {
194- baseUrl = '/' + baseUrl;
195- }
196- return {
197- ...config,
198- datasets: config.datasets.map(d => ({
199- ...d,
200- files: d.files.map(f => ({
201- ...f,
202- url: `${origin}${baseUrl}${f.url}`,
203- })),
204- })),
205- };
192+ }
193+ return {
194+ ...config,
195+ datasets: config.datasets.map(d => ({
196+ ...d,
197+ files: d.files.map(f => {
198+ // Checks to handle different scenarios of urls presented in workspaces and otherwise, i.e., local vs. remote
199+ // For regular urls
200+ let constructedUrl = f.url
201+ // if in workspaces, only local data is accessed
202+ if (isInWorkspaces && f.url.startsWith(WORKSPACES_URL_KEYWORD)){
203+ constructedUrl = `${proxyPath}${baseUrl}${f.url}`
204+ }
205+ else if (isInWorkspaces && !f.url.startsWith(WORKSPACES_URL_KEYWORD)){
206+ constructedUrl = f.url
207+ }
208+ // if local data is accessed in the notebook
209+ else if (f.url.startsWith('proxy')) {
210+ constructedUrl = `${origin}${baseUrl}${f.url}`
211+ }
212+ return {
213+ ...f,
214+ url: constructedUrl,
215+ }
216+ }),
217+ })),
218+ };
206219}
207220
208221async function render(view) {
0 commit comments