Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Fix prefix static source 404 issue #4051

Merged
merged 5 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ts/nni_manager/common/experimentStartupInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions ts/nni_manager/rest_server/nniRestServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()));
Expand All @@ -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'));
});
}
Expand Down
8 changes: 7 additions & 1 deletion ts/webui/src/static/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
Expand Down