Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow VolView to be hosted at non-root url #690

Closed
amazy opened this issue Jan 24, 2025 · 3 comments · Fixed by #694
Closed

Allow VolView to be hosted at non-root url #690

amazy opened this issue Jan 24, 2025 · 3 comments · Fixed by #694

Comments

@amazy
Copy link

amazy commented Jan 24, 2025

Hi,

When packaging VolView in the Orthanc plugin, Orthanc serves VolView at http://localhost:8042/volview/.
In order for this to work, we actually need to patch VolView code with the below patch.

The way we patch it, VolView can then actually be hosted at any url (because it is actually quite often served at something like https://myserver.com/orthanc/volview/).

Could ease our life for future releases if you allow hosting at any url and might be useful for other people too. Or maybe we are wrong and there is already a configuration for this !

Thanks,

Alain.

diff -urEb VolView-4.3.0.orig/src/io/itk/itkConfig.js VolView-4.3.0/src/io/itk/itkConfig.js
--- VolView-4.3.0.orig/src/io/itk/itkConfig.js  2025-01-16 18:46:08.962374027 +0100
+++ VolView-4.3.0/src/io/itk/itkConfig.js       2025-01-17 11:10:48.362129043 +0100
@@ -2,8 +2,15 @@
 
 const base = import.meta.env.BASE_URL;
 
-const fullUrl = (relative) =>
-  new URL(join(base, relative), document.location.origin).href;
+const fullUrl = (relative) => {          // ex: /itk/image-io
+  const u = new URL(document.location);  // ex: http://localhost:8043/orthanc/volview/index.html
+  const origin = u.origin;               // ex: http://localhost:8043
+  let pathParts = u.pathname.split('/'); // ex: ['', 'orthanc', 'volview', 'index.html']
+  pathParts.pop();                       // ex: ['', 'orthanc', 'volview']          
+
+  const url = origin + pathParts.join('/') + relative; // ex http://localhost:8043/orthanc/volview/itk/image-io
+  return url;
+}
 
 const itkConfig = {
   pipelineWorkerUrl: fullUrl('/itk/itk-wasm-pipeline.min.worker.js'),
diff -urEb VolView-4.3.0.orig/vite.config.ts VolView-4.3.0/vite.config.ts
--- VolView-4.3.0.orig/vite.config.ts   2025-01-16 18:46:08.862370324 +0100
+++ VolView-4.3.0/vite.config.ts        2025-01-16 19:12:29.866854537 +0100
@@ -114,6 +114,7 @@
       },
     ],
   },
+
−+  base: './',
   plugins: [
     {
       name: 'virtual-modules',
@PaulHax
Copy link
Collaborator

PaulHax commented Jan 27, 2025

I have been running the build with a CLI arg to configure a base path. VITE_REMOTE_SERVER_URL= npm run build -- --base=/static/built/plugins/volview

But I like your change so that it just works without special config.

PaulHax added a commit to PaulHax/VolView that referenced this issue Jan 27, 2025
@floryst
Copy link
Collaborator

floryst commented Jan 28, 2025

I'm open to this change!

PaulHax added a commit to PaulHax/VolView that referenced this issue Jan 28, 2025
PaulHax added a commit to PaulHax/VolView that referenced this issue Jan 28, 2025
@amazy
Copy link
Author

amazy commented Jan 29, 2025

Great ! Thanks for merging the change !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants