diff --git a/ts/nni_manager/common/experimentStartupInfo.ts b/ts/nni_manager/common/experimentStartupInfo.ts index ee3e80584e..e31169b273 100644 --- a/ts/nni_manager/common/experimentStartupInfo.ts +++ b/ts/nni_manager/common/experimentStartupInfo.ts @@ -126,3 +126,8 @@ export function getDispatcherPipe(): string | null { export function getAPIRootUrl(): string { return getExperimentStartupInfo().apiRootUrl; } + +export function getPrefixUrl(): string { + const prefix = getExperimentStartupInfo().urlprefix === '' ? '' : `/${getExperimentStartupInfo().urlprefix}`; + return prefix; +} diff --git a/ts/nni_manager/rest_server/nniRestServer.ts b/ts/nni_manager/rest_server/nniRestServer.ts index de335af1e1..4b5abcf8d6 100644 --- a/ts/nni_manager/rest_server/nniRestServer.ts +++ b/ts/nni_manager/rest_server/nniRestServer.ts @@ -11,7 +11,7 @@ import * as component from '../common/component'; import { RestServer } from '../common/restServer' import { getLogDir } from '../common/utils'; import { createRestHandler } from './restHandler'; -import { getAPIRootUrl } from '../common/experimentStartupInfo'; +import { getAPIRootUrl, getPrefixUrl } from '../common/experimentStartupInfo'; /** * NNI Main rest server, provides rest API to support @@ -38,7 +38,7 @@ export class NNIRestServer extends RestServer { * NNIRestServer's own router registration */ protected registerRestHandler(): void { - this.app.use(express.static('static')); + this.app.use(getPrefixUrl(), express.static('static')); this.app.use(bodyParser.json({limit: '50mb'})); this.app.use(this.API_ROOT_URL, createRestHandler(this)); this.app.use(this.LOGS_ROOT_URL, express.static(getLogDir())); @@ -50,7 +50,7 @@ export class NNIRestServer extends RestServer { target: 'https://netron.app' }); }); - this.app.get('*', (req: express.Request, res: express.Response) => { + this.app.get(`${getPrefixUrl()}/*`, (req: express.Request, res: express.Response) => { res.sendFile(path.resolve('static/index.html')); }); } diff --git a/ts/webui/src/static/function.ts b/ts/webui/src/static/function.ts index 2654afa325..a72e73062f 100644 --- a/ts/webui/src/static/function.ts +++ b/ts/webui/src/static/function.ts @@ -14,7 +14,13 @@ function getPrefix(): string | undefined { newPathName = pathName.replace(item, ''); } }); - return newPathName === '' || newPathName === '/' ? undefined : newPathName; + let result = newPathName === '' || newPathName === '/' ? undefined : newPathName; + if (result !== undefined) { + if (result.endsWith('/')) { + result = result.slice(0, result.length - 1); + } + } + return result; } async function requestAxios(url: string): Promise {