mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove parameter 'path' of handleStaticFile
Signed-off-by: Hung-Han (Henry) Chen <1474479+chenhunghan@users.noreply.github.com>
This commit is contained in:
1 file changed
+9
-8
+9
-8
@@ -94,13 +94,14 @@ export class Router {
|
|||||||
return mimeTypes[path.extname(filename).slice(1)] || "text/plain"
|
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);
|
const asset = path.join(__static, filePath);
|
||||||
try {
|
try {
|
||||||
const filename = path.basename(requestpath);
|
const filename = path.basename(req.url);
|
||||||
const toWebpackDevServer = filename.includes(appName) || filename.includes('hot-update') || requestpath.includes('sockjs-node')
|
// 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) {
|
if (isDevelopment && toWebpackDevServer) {
|
||||||
const redirectLocation = `http://localhost:${webpackDevServerPort}` + requestpath
|
const redirectLocation = `http://localhost:${webpackDevServerPort}` + req.url;
|
||||||
res.statusCode = 307;
|
res.statusCode = 307;
|
||||||
res.setHeader('Location', redirectLocation);
|
res.setHeader('Location', redirectLocation);
|
||||||
res.end();
|
res.end();
|
||||||
@@ -108,10 +109,10 @@ export class Router {
|
|||||||
}
|
}
|
||||||
const data = await readFile(asset);
|
const data = await readFile(asset);
|
||||||
res.setHeader("Content-Type", this.getMimeType(asset));
|
res.setHeader("Content-Type", this.getMimeType(asset));
|
||||||
res.write(data)
|
res.write(data);
|
||||||
res.end()
|
res.end();
|
||||||
} catch (err) {
|
} 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(
|
this.router.add(
|
||||||
{ method: 'get', path: '/{path*}' },
|
{ method: 'get', path: '/{path*}' },
|
||||||
({ params, response, path, raw: { req }}: LensApiRequest) => {
|
({ 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))
|
this.router.add({ method: "get", path: `${apiPrefix}/kubeconfig/service-account/{namespace}/{account}` }, kubeconfigRoute.routeServiceAccountRoute.bind(kubeconfigRoute))
|
||||||
|
|||||||
Reference in new issue
Block a user