Unverified Commit 0fe0fd86 authored by Ni Hao's avatar Ni Hao Committed by GitHub
Browse files

Fix prefix static source 404 issue (#4051)

parent 23b8e8ab
...@@ -126,3 +126,8 @@ export function getDispatcherPipe(): string | null { ...@@ -126,3 +126,8 @@ export function getDispatcherPipe(): string | null {
export function getAPIRootUrl(): string { export function getAPIRootUrl(): string {
return getExperimentStartupInfo().apiRootUrl; return getExperimentStartupInfo().apiRootUrl;
} }
export function getPrefixUrl(): string {
const prefix = getExperimentStartupInfo().urlprefix === '' ? '' : `/${getExperimentStartupInfo().urlprefix}`;
return prefix;
}
...@@ -11,7 +11,7 @@ import * as component from '../common/component'; ...@@ -11,7 +11,7 @@ import * as component from '../common/component';
import { RestServer } from '../common/restServer' import { RestServer } from '../common/restServer'
import { getLogDir } from '../common/utils'; import { getLogDir } from '../common/utils';
import { createRestHandler } from './restHandler'; import { createRestHandler } from './restHandler';
import { getAPIRootUrl } from '../common/experimentStartupInfo'; import { getAPIRootUrl, getPrefixUrl } from '../common/experimentStartupInfo';
/** /**
* NNI Main rest server, provides rest API to support * NNI Main rest server, provides rest API to support
...@@ -38,7 +38,7 @@ export class NNIRestServer extends RestServer { ...@@ -38,7 +38,7 @@ export class NNIRestServer extends RestServer {
* NNIRestServer's own router registration * NNIRestServer's own router registration
*/ */
protected registerRestHandler(): void { 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(bodyParser.json({limit: '50mb'}));
this.app.use(this.API_ROOT_URL, createRestHandler(this)); this.app.use(this.API_ROOT_URL, createRestHandler(this));
this.app.use(this.LOGS_ROOT_URL, express.static(getLogDir())); this.app.use(this.LOGS_ROOT_URL, express.static(getLogDir()));
...@@ -50,7 +50,7 @@ export class NNIRestServer extends RestServer { ...@@ -50,7 +50,7 @@ export class NNIRestServer extends RestServer {
target: 'https://netron.app' 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')); res.sendFile(path.resolve('static/index.html'));
}); });
} }
......
...@@ -14,7 +14,13 @@ function getPrefix(): string | undefined { ...@@ -14,7 +14,13 @@ function getPrefix(): string | undefined {
newPathName = pathName.replace(item, ''); 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> { async function requestAxios(url: string): Promise<any> {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment