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

Commit

Permalink
Fix prefix static source 404 issue (#4051)
Browse files Browse the repository at this point in the history
  • Loading branch information
acured authored Aug 10, 2021
1 parent 23b8e8a commit 0fe0fd8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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

0 comments on commit 0fe0fd8

Please sign in to comment.