mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
serve react app via router
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
eca33fcc37
commit
5d6826771a
@ -3,7 +3,7 @@
|
||||
import path from "path";
|
||||
import { protocol } from "electron"
|
||||
import logger from "../main/logger";
|
||||
import { staticDir, staticProto } from "./vars";
|
||||
import { staticDir, staticProto, outDir } from "./vars";
|
||||
|
||||
export function registerStaticProtocol(rootFolder = staticDir) {
|
||||
const scheme = staticProto.replace("://", "");
|
||||
@ -23,3 +23,7 @@ export function getStaticUrl(filePath: string) {
|
||||
export function getStaticPath(filePath: string) {
|
||||
return path.resolve(staticDir, filePath);
|
||||
}
|
||||
|
||||
export function getOutPath(filePath: string) {
|
||||
return path.resolve(outDir, filePath);
|
||||
}
|
||||
|
||||
@ -8,9 +8,6 @@ import { KubeAuthProxy } from "./kube-auth-proxy"
|
||||
import { Cluster, ClusterPreferences } from "./cluster"
|
||||
import { prometheusProviders } from "../common/prometheus-providers"
|
||||
import { PrometheusProvider, PrometheusService } from "./prometheus/provider-registry"
|
||||
import { reactAppName } from "../common/vars"
|
||||
import path from "path"
|
||||
import { format as formatUrl } from "url"
|
||||
|
||||
export class ContextHandler {
|
||||
public contextName: string
|
||||
@ -59,12 +56,7 @@ export class ContextHandler {
|
||||
this.clusterUrl = url.parse(kc.getCurrentCluster().server)
|
||||
this.contextName = kc.currentContext;
|
||||
this.defaultNamespace = kc.getContextObject(kc.currentContext).namespace
|
||||
//this.url = `http://${this.id}.localhost:${cluster.port}/`
|
||||
this.url = formatUrl({
|
||||
pathname: path.join(__dirname, `${reactAppName}.html`),
|
||||
protocol: "file",
|
||||
slashes: true,
|
||||
})
|
||||
this.url = `http://${this.id}.localhost:${cluster.port}/`
|
||||
this.kubernetesApi = `http://127.0.0.1:${cluster.port}/${this.id}`
|
||||
this.kc.clusters = [
|
||||
{
|
||||
|
||||
@ -9,7 +9,7 @@ import { kubeconfigRoute } from "./routes/kubeconfig"
|
||||
import { metricsRoute } from "./routes/metrics"
|
||||
import { watchRoute } from "./routes/watch"
|
||||
import { portForwardRoute } from "./routes/port-forward"
|
||||
import { getStaticPath } from "../common/register-static";
|
||||
import { getOutPath } from "../common/register-static";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const Call = require('@hapi/call');
|
||||
@ -86,11 +86,11 @@ export class Router {
|
||||
}
|
||||
|
||||
protected handleStaticFile(filePath: string, response: http.ServerResponse) {
|
||||
const asset = getStaticPath(filePath);
|
||||
const asset = getOutPath(filePath);
|
||||
readFile(asset, (err, data) => {
|
||||
if (err) {
|
||||
// default to index.html so that react routes work when page is refreshed
|
||||
this.handleStaticFile("index.html", response)
|
||||
this.handleStaticFile("app_react.html", response)
|
||||
} else {
|
||||
const type = mimeTypes[path.extname(asset).slice(1)] || "text/plain";
|
||||
response.setHeader("Content-Type", type);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user