Skip to content

Commit 303ff9d

Browse files
fit2botw940853815github-actions[bot]
authored
feat: configurable url prefix (#1509)
* 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>
1 parent 64e9732 commit 303ff9d

22 files changed

Lines changed: 320 additions & 61 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use base image to build the project avoid npm install every time
2-
FROM jumpserver/luna-base:20250609_105214 AS stage-build
2+
FROM jumpserver/luna-base:20260320_114803 AS stage-build
33

44
ARG VERSION
55
ENV VERSION=$VERSION

angular.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"aot": false,
1919
"sourceMap": true,
2020
"namedChunks": true,
21+
"baseHref": "/luna/",
2122
"index": "src/index.html",
2223
"browser": "src/main.ts",
2324
"polyfills": ["src/polyfills.ts"],
@@ -101,7 +102,8 @@
101102
"builder": "@angular/build:dev-server",
102103
"options": {
103104
"buildTarget": "Luna:build",
104-
"proxyConfig": "proxy.conf.json"
105+
"proxyConfig": "proxy.conf.json",
106+
"servePath": "/luna"
105107
},
106108
"configurations": {
107109
"production": {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"license": "GPLv3",
55
"scripts": {
66
"ng": "ng",
7-
"dev": "ng serve --proxy-config proxy.conf.json --hmr --host 0.0.0.0",
8-
"start": "ng serve --proxy-config proxy.conf.json --host 0.0.0.0",
7+
"dev": "ng serve --proxy-config proxy.conf.json --serve-path /luna --hmr --host 0.0.0.0",
8+
"start": "ng serve --proxy-config proxy.conf.json --serve-path /luna --host 0.0.0.0",
99
"build": "ng build --configuration production",
1010
"test": "ng test",
1111
"lint": "ng lint",

src/app/app.module.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,19 @@ import { AppComponent } from './pages/app.component';
2020
import { ElementComponents } from './elements/elements.component';
2121
import { PluginModules } from './plugins/plugins';
2222
import { ClipboardService } from 'ngx-clipboard';
23-
import { environment, version } from '../environments/environment';
23+
import { version } from '../environments/environment';
2424
import { BehaviorSubject, forkJoin, Observable, of } from 'rxjs';
2525
import { FileInputAccessorModule } from 'file-input-accessor';
2626
import { catchError, mergeMap } from 'rxjs/operators';
2727
import { PagesComponents } from './pages/pages.component';
28+
import { getAppBasePath, withAppBase, withSitePrefix } from '@app/utils/path';
2829

2930
export class CustomLoader implements TranslateLoader {
3031
constructor(private http: HttpClient) {}
3132

3233
public getTranslation(lang: String): Observable<any> {
33-
const remote = '/api/v1/settings/i18n/luna/?lang=' + lang + '&v=' + version;
34-
let local = '/assets/i18n/' + lang + '.json';
35-
const isProd = environment.production;
36-
if (isProd) {
37-
local = '/luna' + local;
38-
}
34+
const remote = withSitePrefix('/api/v1/settings/i18n/luna/?lang=' + lang + '&v=' + version);
35+
const local = withAppBase('/assets/i18n/' + lang + '.json');
3936

4037
return forkJoin([
4138
this.http.get(remote).pipe(catchError(() => of({}))),
@@ -74,7 +71,7 @@ export class CustomLoader implements TranslateLoader {
7471
bootstrap: [AppComponent],
7572
providers: [
7673
...AllServices,
77-
{ provide: APP_BASE_HREF, useValue: '/luna/' },
74+
{ provide: APP_BASE_HREF, useFactory: getAppBasePath },
7875
CookieService,
7976
NGXLogger,
8077
ClipboardService,

src/app/elements/chat/chat.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
HostListener,
1616
AfterViewInit
1717
} from '@angular/core';
18+
import { withUIBase } from '@app/utils/path';
1819

1920
@Component({
2021
standalone: false,
@@ -157,7 +158,7 @@ export class ElementChatComponent implements OnInit, OnDestroy, AfterViewInit {
157158
}
158159

159160
private listenChatAI(): void {
160-
this.iframeURL = '/ui/#/chat/chat-ai?from=luna';
161+
this.iframeURL = withUIBase('#/chat/chat-ai?from=luna');
161162

162163
window.addEventListener('message', event => {
163164
// 确认消息的来源是你信任的域

src/app/elements/connect/download-dialog/download-dialog.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component, Inject, OnInit} from '@angular/core';
22
import {NZ_MODAL_DATA} from "ng-zorro-antd/modal";
3+
import {withSitePrefix} from '@app/utils/path';
34

45
@Component({
56
standalone: false,
@@ -32,6 +33,6 @@ export class ElementDownloadDialogComponent implements OnInit {
3233
if (this.ignoreRemind) {
3334
localStorage.setItem('hasDownLoadApp', '1');
3435
}
35-
window.open('/core/download/', '_blank');
36+
window.open(withSitePrefix('/core/download/'), '_blank');
3637
}
3738
}

src/app/elements/content/content-window/default/default.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
22
import {Asset, Endpoint, View} from '@app/model';
3+
import {joinEndpointUrl} from '@app/utils/path';
34

45
@Component({
56
standalone: false,
@@ -40,16 +41,16 @@ export class ElementConnectorDefaultComponent implements OnInit {
4041
const token = this.view.connectToken.id;
4142
switch (this.connector) {
4243
case 'chen':
43-
const url = `${endpointUrl}/chen/connect?token=${token}`;
44+
const url = joinEndpointUrl(endpointUrl, `/chen/connect?token=${token}`);
4445
const disableautohash = this.view.getConnectOption('disableautohash');
4546
if (disableautohash) {
4647
return `${url}&disableautohash=true`;
4748
}
4849
return url;
4950
case 'lion':
50-
return `${endpointUrl}/lion/connect?token=${token}`;
51+
return joinEndpointUrl(endpointUrl, `/lion/connect?token=${token}`);
5152
case 'default':
52-
return `${endpointUrl}/koko/connect?token=${token}`;
53+
return joinEndpointUrl(endpointUrl, `/koko/connect?token=${token}`);
5354
}
5455
}
5556
}

src/app/elements/content/content-window/koko/koko.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@app/services';
1010
import { User } from '@app/globals';
1111
import { Command, InfoItem } from '../guide/model';
12+
import { joinEndpointUrl } from '@app/utils/path';
1213

1314
@Component({
1415
standalone: false,
@@ -54,7 +55,7 @@ export class ElementConnectorKokoComponent implements OnInit {
5455
this.account = account;
5556
this.token = connectToken;
5657
const url = smartEndpoint.getUrl();
57-
this.baseUrl = `${url}/koko`;
58+
this.baseUrl = url;
5859
this.methodName = this.view.connectMethod.value;
5960
if (this.methodName === 'ssh_guide') {
6061
this.setInfoItems();
@@ -165,14 +166,17 @@ export class ElementConnectorKokoComponent implements OnInit {
165166
});
166167

167168
if (this.protocol === 'k8s') {
168-
return (this.iframeURL = `${this.baseUrl}/k8s/?` + query);
169+
return (this.iframeURL = joinEndpointUrl(this.baseUrl, `/koko/k8s/?${query}`));
169170
}
170171

171-
this.iframeURL = `${this.baseUrl}/connect/?` + query;
172+
this.iframeURL = joinEndpointUrl(this.baseUrl, `/koko/connect/?${query}`);
172173
}
173174

174175
generateFileManagerURL() {
175-
this.iframeURL = `${this.baseUrl}/elfinder/sftp/?token=${this.view.connectToken.id}&asset=${this.asset.id}`;
176+
this.iframeURL = joinEndpointUrl(
177+
this.baseUrl,
178+
`/koko/elfinder/sftp/?token=${this.view.connectToken.id}&asset=${this.asset.id}`
179+
);
176180
}
177181

178182
async reconnect() {

src/app/elements/nav/nav.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
SettingService,
1313
ViewService
1414
} from '@app/services';
15+
import { withSitePrefix, withUIBase } from '@app/utils/path';
1516

1617
@Component({
1718
standalone: false,
@@ -59,7 +60,7 @@ export class ElementNavComponent implements OnInit {
5960
{
6061
id: 'Connect',
6162
click: () => {
62-
window.open('/koko/elfinder/sftp/');
63+
window.open(withSitePrefix('/koko/elfinder/sftp/'));
6364
},
6465
name: 'Connect'
6566
}
@@ -171,7 +172,7 @@ export class ElementNavComponent implements OnInit {
171172
{
172173
id: 'Download',
173174
click: () => {
174-
window.open('/core/download/', '_blank');
175+
window.open(withSitePrefix('/core/download/'), '_blank');
175176
},
176177
name: 'Download'
177178
}
@@ -217,6 +218,6 @@ export class ElementNavComponent implements OnInit {
217218
}
218219

219220
onJumpUi() {
220-
window.open('/ui/', '_blank');
221+
window.open(withUIBase(), '_blank');
221222
}
222223
}

src/app/elements/nav/profile/profile.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Component, OnInit} from '@angular/core';
22
import {HttpService} from '@app/services';
33
import {User} from '@app/globals';
44
import {User as ModelUser} from '@app/model';
5+
import {withSitePrefix} from '@app/utils/path';
56

67
interface MenuItem {
78
id: string;
@@ -33,7 +34,7 @@ export class ElementUserFileComponent implements OnInit {
3334
id: 'logout',
3435
name: 'Log out',
3536
click: () => {
36-
window.location.href = document.location.origin + '/core/auth/logout/';
37+
window.location.href = withSitePrefix('/core/auth/logout/');
3738
},
3839
}
3940
];

0 commit comments

Comments
 (0)