1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix apiBase initialization on main (#3595)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-08-12 10:34:45 +03:00 committed by GitHub
parent 37ec55c243
commit 443186d4f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -23,19 +23,28 @@ import { JsonApi } from "./json-api";
import { KubeJsonApi } from "./kube-json-api";
import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars";
import { isClusterPageContext } from "../utils/cluster-id-url-parsing";
import { appEventBus } from "../event-bus";
let apiBase: JsonApi;
let apiKube: KubeJsonApi;
if (typeof window === "undefined") {
apiBase = new JsonApi({
serverAddress: `http://127.0.0.1:${process.env.LENS_PROXY_PORT}`,
apiBase: apiPrefix,
debug: isDevelopment || isDebugging,
}, {
headers: {
"Host": `localhost:${process.env.LENS_PROXY_PORT}`
}
appEventBus.addListener((event) => {
if (event.name !== "lens-proxy" && event.action !== "listen") return;
const params = event.params as { port?: number };
if (!params.port) return;
apiBase = new JsonApi({
serverAddress: `http://127.0.0.1:${params.port}`,
apiBase: apiPrefix,
debug: isDevelopment || isDebugging,
}, {
headers: {
"Host": `localhost:${params.port}`
}
});
});
} else {
apiBase = new JsonApi({

View File

@ -96,13 +96,14 @@ export interface IKubeApiCluster {
}
export function forCluster<T extends KubeObject>(cluster: IKubeApiCluster, kubeClass: KubeObjectConstructor<T>): KubeApi<T> {
const url = new URL(apiBase.config.serverAddress);
const request = new KubeJsonApi({
serverAddress: apiBase.config.serverAddress,
apiBase: apiKubePrefix,
debug: isDevelopment,
}, {
headers: {
"Host": apiBase.config.serverAddress
"Host": `${cluster.metadata.uid}.localhost:${url.port}`
}
});

View File

@ -30,6 +30,7 @@ import logger from "./logger";
import { Singleton } from "../common/utils";
import type { Cluster } from "./cluster";
import type { ProxyApiRequestArgs } from "./proxy-functions";
import { appEventBus } from "../common/event-bus";
type GetClusterForRequest = (req: http.IncomingMessage) => Cluster | null;
@ -97,7 +98,7 @@ export class LensProxy extends Singleton {
});
this.port = port;
process.env.LENS_PROXY_PORT = port.toString();
appEventBus.emit({ name: "lens-proxy", action: "listen", params: { port }});
resolve();
})
.once("error", (error) => {