fix apiBase initialization on main (#3595)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2021-08-12 10:34:45 +03:00
1 parent 37ec55c243
commit 443186d4f5
3 files changed
+21 -10

No files matched your search

+17 -8
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({
+2 -1
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}`
}
});