From b87e3032af22913cfe2421e564ce42e1bb6004d9 Mon Sep 17 00:00:00 2001 From: "Hung-Han (Henry) Chen" <1474479+chenhunghan@users.noreply.github.com> Date: Mon, 9 Nov 2020 17:34:29 +0800 Subject: [PATCH] Remove parameter 'path' of handleStaticFile Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com> --- src/main/router.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/router.ts b/src/main/router.ts index 86ec2c1cb0..a5323bf150 100644 --- a/src/main/router.ts +++ b/src/main/router.ts @@ -94,13 +94,14 @@ export class Router { return mimeTypes[path.extname(filename).slice(1)] || "text/plain" } - async handleStaticFile(filePath: string, res: http.ServerResponse, requestpath: string, req: http.IncomingMessage) { + async handleStaticFile(filePath: string, res: http.ServerResponse, req: http.IncomingMessage) { const asset = path.join(__static, filePath); try { - const filename = path.basename(requestpath); - const toWebpackDevServer = filename.includes(appName) || filename.includes('hot-update') || requestpath.includes('sockjs-node') + const filename = path.basename(req.url); + // redirect requests to [appName].js, [appName].html /sockjs-node/ to webpack-dev-server (for hot-reload support) + const toWebpackDevServer = filename.includes(appName) || filename.includes('hot-update') || req.url.includes('sockjs-node'); if (isDevelopment && toWebpackDevServer) { - const redirectLocation = `http://localhost:${webpackDevServerPort}` + requestpath + const redirectLocation = `http://localhost:${webpackDevServerPort}` + req.url; res.statusCode = 307; res.setHeader('Location', redirectLocation); res.end(); @@ -108,10 +109,10 @@ export class Router { } const data = await readFile(asset); res.setHeader("Content-Type", this.getMimeType(asset)); - res.write(data) - res.end() + res.write(data); + res.end(); } catch (err) { - this.handleStaticFile(`${publicPath}/${appName}.html`, res, requestpath, req); + this.handleStaticFile(`${publicPath}/${appName}.html`, res, req); } } @@ -120,7 +121,7 @@ export class Router { this.router.add( { method: 'get', path: '/{path*}' }, ({ params, response, path, raw: { req }}: LensApiRequest) => { - this.handleStaticFile(params.path, response, path, req); + this.handleStaticFile(params.path, response, req); }); this.router.add({ method: "get", path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}` }, kubeconfigRoute.routeServiceAccountRoute.bind(kubeconfigRoute))