From 79abfe49d9bad0c11add8a74758aa765d1aec7fb Mon Sep 17 00:00:00 2001 From: "Hung-Han (Henry) Chen" <1474479+chenhunghan@users.noreply.github.com> Date: Thu, 5 Nov 2020 20:46:12 +0800 Subject: [PATCH] Serve statics using webpack-dev-server instead of lens-proxy, redirect request of Lens.html/Lens.js to webpack-dev-server Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com> --- src/main/router.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/router.ts b/src/main/router.ts index 976d7cac9c..61478c2ba0 100644 --- a/src/main/router.ts +++ b/src/main/router.ts @@ -94,9 +94,16 @@ export class Router { return mimeTypes[path.extname(filename).slice(1)] || "text/plain" } - async handleStaticFile(filePath: string, res: http.ServerResponse) { + async handleStaticFile(filePath: string, res: http.ServerResponse, requestpath?: string) { const asset = path.join(__static, filePath); try { + if (path.basename(requestpath).includes(appName)) { + res.writeHead(307, + { Location: 'http://localhost:9000' + requestpath } + ); + res.end(); + return; + } const data = await readFile(asset); res.setHeader("Content-Type", this.getMimeType(asset)); res.write(data) @@ -108,8 +115,8 @@ export class Router { protected addRoutes() { // Static assets - this.router.add({ method: 'get', path: '/{path*}' }, ({ params, response }: LensApiRequest) => { - this.handleStaticFile(params.path, response); + this.router.add({ method: 'get', path: '/{path*}' }, ({ params, response, path }: LensApiRequest) => { + this.handleStaticFile(params.path, response, path); }); this.router.add({ method: "get", path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}` }, kubeconfigRoute.routeServiceAccountRoute.bind(kubeconfigRoute))