From 388587f02294240d5ba575661b95c1cb270a5afa Mon Sep 17 00:00:00 2001 From: Hao Ni Date: Tue, 10 Aug 2021 11:27:40 +0800 Subject: [PATCH 1/5] fix prefix static resource files 404 error --- ts/nni_manager/common/experimentStartupInfo.ts | 5 +++++ ts/nni_manager/rest_server/nniRestServer.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ts/nni_manager/common/experimentStartupInfo.ts b/ts/nni_manager/common/experimentStartupInfo.ts index ee3e80584e..9b81a24ca7 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..e89e5ccf95 100644 --- a/ts/nni_manager/rest_server/nniRestServer.ts +++ b/ts/nni_manager/rest_server/nniRestServer.ts @@ -11,7 +11,10 @@ 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'; +import { getLogger } from '../common/log'; + +var log = getLogger('NNIManager'); /** * NNI Main rest server, provides rest API to support @@ -38,7 +41,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 +53,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')); }); } From 4b5908471f8ab43495af457f7339266c8b386d06 Mon Sep 17 00:00:00 2001 From: Hao Ni Date: Tue, 10 Aug 2021 15:00:01 +0800 Subject: [PATCH 2/5] update UI method(from Lijiao) --- ts/webui/src/static/function.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 { From 9eb23aea8c5f630fe4ddd84ac29430709772f7bb Mon Sep 17 00:00:00 2001 From: Hao Ni Date: Tue, 10 Aug 2021 15:02:13 +0800 Subject: [PATCH 3/5] remove unused code --- ts/nni_manager/rest_server/nniRestServer.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/ts/nni_manager/rest_server/nniRestServer.ts b/ts/nni_manager/rest_server/nniRestServer.ts index e89e5ccf95..a92353c737 100644 --- a/ts/nni_manager/rest_server/nniRestServer.ts +++ b/ts/nni_manager/rest_server/nniRestServer.ts @@ -12,9 +12,6 @@ import { RestServer } from '../common/restServer' import { getLogDir } from '../common/utils'; import { createRestHandler } from './restHandler'; import { getAPIRootUrl, getPrefixUrl } from '../common/experimentStartupInfo'; -import { getLogger } from '../common/log'; - -var log = getLogger('NNIManager'); /** * NNI Main rest server, provides rest API to support From 8a690d898f852cb55adc7ea96cf00c17c8262a29 Mon Sep 17 00:00:00 2001 From: Hao Ni Date: Tue, 10 Aug 2021 15:16:39 +0800 Subject: [PATCH 4/5] fix missing semicolon --- ts/nni_manager/rest_server/nniRestServer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/nni_manager/rest_server/nniRestServer.ts b/ts/nni_manager/rest_server/nniRestServer.ts index a92353c737..4b5abcf8d6 100644 --- a/ts/nni_manager/rest_server/nniRestServer.ts +++ b/ts/nni_manager/rest_server/nniRestServer.ts @@ -38,7 +38,7 @@ export class NNIRestServer extends RestServer { * NNIRestServer's own router registration */ protected registerRestHandler(): void { - this.app.use(getPrefixUrl(), 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())); From c1c8ef8c6ec415771f7cf602968f3366e9cd5dbb Mon Sep 17 00:00:00 2001 From: Hao Ni Date: Tue, 10 Aug 2021 15:21:25 +0800 Subject: [PATCH 5/5] fix style --- ts/nni_manager/common/experimentStartupInfo.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/nni_manager/common/experimentStartupInfo.ts b/ts/nni_manager/common/experimentStartupInfo.ts index 9b81a24ca7..e31169b273 100644 --- a/ts/nni_manager/common/experimentStartupInfo.ts +++ b/ts/nni_manager/common/experimentStartupInfo.ts @@ -128,6 +128,6 @@ export function getAPIRootUrl(): string { } export function getPrefixUrl(): string { - const prefix = getExperimentStartupInfo().urlprefix === ''?'':`/${getExperimentStartupInfo().urlprefix}`; + const prefix = getExperimentStartupInfo().urlprefix === '' ? '' : `/${getExperimentStartupInfo().urlprefix}`; return prefix; }