feat: configurable url prefix (#1509) - #1512
Conversation
* feat: configurable url prefix * perf: Update Dockerfile with new base image tag --------- Co-authored-by: wangruidong <940853815@qq.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
|
There was a problem hiding this comment.
Pull request overview
Adds support for running the Luna UI under an additional configurable site URL prefix (e.g., /prefix/luna/) by centralizing URL/base-path construction, and updates the Docker build base image tag.
Changes:
- Add runtime base-path detection in
index.htmland expose computed bases viawindow.__*globals. - Introduce
@app/utils/pathhelpers and update UI/API/link construction across the app to use them. - Update Angular dev/build baseHref/servePath and bump the Docker
luna-basetag.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/typings.d.ts | Adds typings for new window.__BASE_PATH__, __UI_BASE__, __LUNA_BASE__ globals. |
| src/index.html | Computes and sets <base> and global base-path variables at runtime. |
| src/app/utils/path.ts | New centralized helpers for deriving base paths and joining prefixed URLs. |
| src/app/utils/common.ts | Uses withAppBase() for connect URL generation. |
| src/app/services/http.ts | Prefixes root-relative API URLs and updates login redirect URL construction. |
| src/app/services/connect-token/acl-dialog/acl-dialog.component.ts | Uses withUIBase() for UI link generation. |
| src/app/services/app.ts | Updates login navigation and route handling for prefixed deployments. |
| src/app/pages/share/share.component.ts | Uses withSitePrefix() for share iframe URLs. |
| src/app/pages/sftp/sftp.component.ts | Uses withSitePrefix() for SFTP iframe URL. |
| src/app/pages/monitor/monitor.component.ts | Uses joinEndpointUrl() for monitor iframe URLs. |
| src/app/pages/main/main.component.ts | Uses toAbsoluteWsUrl() and withAppBase() for ws/replay pathing. |
| src/app/pages/kubernetes/kubernetes.component.ts | Uses withSitePrefix() for k8s iframe URL. |
| src/app/elements/nav/profile/profile.component.ts | Uses withSitePrefix() for logout URL. |
| src/app/elements/nav/nav.component.ts | Uses withSitePrefix() / withUIBase() for external opens. |
| src/app/elements/content/content-window/koko/koko.component.ts | Uses joinEndpointUrl() and removes hard-coded /koko base concatenation. |
| src/app/elements/content/content-window/default/default.component.ts | Uses joinEndpointUrl() for connector URLs. |
| src/app/elements/connect/download-dialog/download-dialog.component.ts | Uses withSitePrefix() for download URL. |
| src/app/elements/chat/chat.component.ts | Uses withUIBase() for chat iframe URL. |
| src/app/app.module.ts | Uses path helpers for i18n URLs and makes APP_BASE_HREF dynamic via getAppBasePath(). |
| package.json | Adjusts ng serve scripts to use /luna serve path. |
| angular.json | Sets baseHref and dev-server servePath for /luna. |
| Dockerfile | Updates jumpserver/luna-base image tag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function isAbsoluteUrl(url: string): boolean { | ||
| return /^[a-z][a-z\d+\-.]*:\/\//i.test(url) || url.startsWith('//'); | ||
| } | ||
|
|
||
| function normalizeBasePath(path = '/'): string { | ||
| let normalizedPath = path || '/'; | ||
|
|
||
| if (isAbsoluteUrl(normalizedPath)) { | ||
| normalizedPath = new URL(normalizedPath).pathname; | ||
| } |
There was a problem hiding this comment.
normalizeBasePath()/normalizePrefix() treat protocol-relative URLs (//host/path) as absolute via isAbsoluteUrl(), but then call new URL(normalizedPath) without a base. new URL('//host/path') throws, so passing protocol-relative values will crash at runtime. Use new URL(normalizedPath, window.location.origin) (or similar) when parsing absolute URLs to safely support the //... case, or remove url.startsWith('//') from isAbsoluteUrl() if it isn't intended to be supported.
| var pathname = window.location.pathname || '/'; | ||
| var marker = '/luna/'; | ||
| var idx = pathname.indexOf(marker); | ||
| var prefix = ''; |
There was a problem hiding this comment.
In the <script> block, the '/luna/' marker is hard-coded, while the app segment is separately hard-coded as APP_SEGMENT = 'luna' in @app/utils/path. This duplicates the routing/base-path source of truth and can silently break if the segment ever changes. Consider deriving both from a single constant (e.g., a build-time env var) or making the runtime script read the existing <base> value instead of re-encoding the segment.
| private resolveUrl(url: string): string { | ||
| if (!url || typeof url !== 'string' || !url.startsWith('/')) { | ||
| return url; | ||
| } | ||
|
|
||
| return withSitePrefix(url); | ||
| } |
There was a problem hiding this comment.
resolveUrl(url: string) contains a runtime guard typeof url !== 'string', but the parameter is already typed as string, so this branch is effectively dead code and can hide real call-site typing issues. Either tighten call sites to always pass strings and simplify the guard to just if (!url.startsWith('/')) return url;, or widen the parameter type to unknown/any if non-string inputs are expected.
* feat: configurable url prefix (#1509) (#1512) * feat: configurable url prefix * perf: Update Dockerfile with new base image tag --------- Co-authored-by: fit2bot <68588906+fit2bot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * perf: update build base image * perf: update base image * feat:support proxy site prefix (#1516) Co-authored-by: Crane.z <1481445951@qq.com> * fix: share session page not load favicon * style:make web terminal logo smaller * feat: Added a feature for important message notifications * fix: fullscreen issue * fix: modify remember password through config * fix:Modify the split-screen logic for asset connection * fix:Make the guide function work properly * chore: update github action * deps: update some dep pkgs * fix: client detection * fix: version display * fix: strip build suffix and trailing content from version display * perf: Update Dockerfile with new base image tag --------- Co-authored-by: wrd <w940853815@gmail.com> Co-authored-by: fit2bot <68588906+fit2bot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: ibuler <ibuler@qq.com> Co-authored-by: Crane.z <1481445951@qq.com> Co-authored-by: Bai <baijiangjie@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat: configurable url prefix (#1509) (#1512) * feat: configurable url prefix * perf: Update Dockerfile with new base image tag --------- Co-authored-by: fit2bot <68588906+fit2bot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * perf: update build base image * perf: update base image * feat:support proxy site prefix (#1516) Co-authored-by: Crane.z <1481445951@qq.com> * fix: share session page not load favicon * style:make web terminal logo smaller * feat: Added a feature for important message notifications * fix: fullscreen issue * fix: modify remember password through config * fix:Modify the split-screen logic for asset connection * fix:Make the guide function work properly * chore: update github action * deps: update some dep pkgs * fix: client detection * perf: update support ssh key (#1528) * feat: add support for SSH key authentication in connect dialog * perf: update support ssh key * perf: Update Dockerfile with new base image tag --------- Co-authored-by: wan92hen <wangzhen@fit2cloud.com> Co-authored-by: ibuler <ibuler@qq.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * fix: version display * fix: strip build suffix and trailing content from version display --------- Co-authored-by: wrd <w940853815@gmail.com> Co-authored-by: fit2bot <68588906+fit2bot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: ibuler <ibuler@qq.com> Co-authored-by: Crane.z <1481445951@qq.com> Co-authored-by: Bai <baijiangjie@gmail.com> Co-authored-by: wan92hen <wangzhen@fit2cloud.com>



feat: configurable url prefix
perf: Update Dockerfile with new base image tag