-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(app): support runtime base paths for subpath deployments #5969
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
base: master
Are you sure you want to change the base?
Changes from all commits
c1cfff8
4af85a5
7d9400f
d7b4934
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,86 @@ | |
| name="msapplication-TileColor" | ||
| content="#fff" | ||
| /> | ||
| <script type="text/javascript"> | ||
| (function () { | ||
| // Keep this inline runtime base-path bootstrap in sync with | ||
| // platform/core/src/utils/publicUrl.ts. | ||
| function normalizePublicUrl(value) { | ||
| var rawValue = typeof value === 'string' ? value.trim() : ''; | ||
|
|
||
| if (!rawValue || rawValue === '.') { | ||
| return '/'; | ||
| } | ||
|
|
||
| var normalized = rawValue.replace(/\\/g, '/'); | ||
|
|
||
| if (!normalized.startsWith('/')) { | ||
| normalized = '/' + normalized; | ||
| } | ||
|
|
||
| normalized = normalized.replace(/\/{2,}/g, '/'); | ||
|
|
||
| if (!normalized.endsWith('/')) { | ||
| normalized += '/'; | ||
| } | ||
|
|
||
| return normalized; | ||
| } | ||
|
|
||
| function getLocationBasePathFromPathname(pathname) { | ||
| var locationPath = typeof pathname === 'string' && pathname.length > 0 ? pathname : '/'; | ||
| var lowerPath = locationPath.toLowerCase(); | ||
| var viewerIndex = lowerPath.lastIndexOf('/viewer'); | ||
|
|
||
| if (viewerIndex >= 0) { | ||
| return normalizePublicUrl(locationPath.substring(0, viewerIndex)); | ||
| } | ||
|
|
||
| if (lowerPath.endsWith('/index.html')) { | ||
| return normalizePublicUrl( | ||
| locationPath.substring(0, locationPath.length - '/index.html'.length) | ||
| ); | ||
| } | ||
|
|
||
| if (locationPath === '/') { | ||
| return '/'; | ||
| } | ||
|
|
||
| var lastSegment = locationPath.substring(locationPath.lastIndexOf('/') + 1); | ||
| if (lastSegment.indexOf('.') !== -1) { | ||
| return normalizePublicUrl(locationPath.substring(0, locationPath.lastIndexOf('/'))); | ||
| } | ||
|
|
||
| return normalizePublicUrl(locationPath); | ||
| } | ||
|
Comment on lines
+63
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🐛 Proposed fix var viewerIndex = lowerPath.lastIndexOf('/viewer');
- if (viewerIndex >= 0) {
+ var afterViewer = lowerPath.charAt(viewerIndex + '/viewer'.length);
+ if (viewerIndex >= 0 && (afterViewer === '' || afterViewer === '/')) {
return normalizePublicUrl(locationPath.substring(0, viewerIndex));
}🤖 Prompt for AI Agents |
||
|
|
||
| function resolveRuntimeBasePathFromWindow() { | ||
| var explicitBasePath = | ||
| window.__OHIF_BASE_PATH__ || | ||
| window.PUBLIC_URL || | ||
| (window.config && window.config.routerBasename); | ||
|
|
||
| if (typeof explicitBasePath === 'string' && explicitBasePath.trim().length > 0) { | ||
| return normalizePublicUrl(explicitBasePath); | ||
| } | ||
|
|
||
| return getLocationBasePathFromPathname(window.location.pathname || '/'); | ||
| } | ||
|
|
||
| var basePath = resolveRuntimeBasePathFromWindow(); | ||
|
|
||
| window.__OHIF_BASE_PATH__ = basePath; | ||
| window.PUBLIC_URL = basePath; | ||
|
|
||
| var baseElement = document.querySelector('base'); | ||
| if (!baseElement) { | ||
| baseElement = document.createElement('base'); | ||
| document.head.appendChild(baseElement); | ||
| } | ||
|
|
||
| baseElement.setAttribute('href', basePath); | ||
| })(); | ||
| </script> | ||
| <meta | ||
| name="msapplication-TileImage" | ||
| content="<%= PUBLIC_URL %>assets/mstile-144x144.png" | ||
|
|
@@ -178,10 +258,6 @@ | |
| rel="yandex-tableau-widget" | ||
| href="<%= PUBLIC_URL %>assets/yandex-browser-manifest.json" | ||
| /> | ||
|
|
||
| <script type="text/javascript"> | ||
| window.PUBLIC_URL = '<%= PUBLIC_URL %>'; | ||
| </script> | ||
| <script | ||
| type="text/javascript" | ||
| src="<%= PUBLIC_URL %>app-config.js" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* global __webpack_public_path__ */ | ||
|
|
||
| import { | ||
| normalizePublicUrl, | ||
| toRouterBasename, | ||
| resolveRuntimeBasePathFromWindow, | ||
| } from '@ohif/core'; | ||
|
|
||
| const runtimePublicUrl = resolveRuntimeBasePathFromWindow(); | ||
|
|
||
| window.__OHIF_BASE_PATH__ = runtimePublicUrl; | ||
| window.PUBLIC_URL = runtimePublicUrl; | ||
|
|
||
| if (window.config && !window.config.routerBasename) { | ||
| window.config.routerBasename = toRouterBasename(runtimePublicUrl); | ||
| } | ||
|
|
||
| __webpack_public_path__ = runtimePublicUrl; | ||
|
|
||
| export { | ||
| normalizePublicUrl, | ||
| toRouterBasename, | ||
| resolveRuntimeBasePathFromWindow as resolveRuntimeBasePath, | ||
| runtimePublicUrl, | ||
| }; | ||
|
|
||
| export default runtimePublicUrl; |
Uh oh!
There was an error while loading. Please reload this page.