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:
parent
37ec55c243
commit
443186d4f5
@ -23,19 +23,28 @@ import { JsonApi } from "./json-api";
|
|||||||
import { KubeJsonApi } from "./kube-json-api";
|
import { KubeJsonApi } from "./kube-json-api";
|
||||||
import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars";
|
import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars";
|
||||||
import { isClusterPageContext } from "../utils/cluster-id-url-parsing";
|
import { isClusterPageContext } from "../utils/cluster-id-url-parsing";
|
||||||
|
import { appEventBus } from "../event-bus";
|
||||||
|
|
||||||
let apiBase: JsonApi;
|
let apiBase: JsonApi;
|
||||||
let apiKube: KubeJsonApi;
|
let apiKube: KubeJsonApi;
|
||||||
|
|
||||||
if (typeof window === "undefined") {
|
if (typeof window === "undefined") {
|
||||||
apiBase = new JsonApi({
|
appEventBus.addListener((event) => {
|
||||||
serverAddress: `http://127.0.0.1:${process.env.LENS_PROXY_PORT}`,
|
if (event.name !== "lens-proxy" && event.action !== "listen") return;
|
||||||
apiBase: apiPrefix,
|
|
||||||
debug: isDevelopment || isDebugging,
|
const params = event.params as { port?: number };
|
||||||
}, {
|
|
||||||
headers: {
|
if (!params.port) return;
|
||||||
"Host": `localhost:${process.env.LENS_PROXY_PORT}`
|
|
||||||
}
|
apiBase = new JsonApi({
|
||||||
|
serverAddress: `http://127.0.0.1:${params.port}`,
|
||||||
|
apiBase: apiPrefix,
|
||||||
|
debug: isDevelopment || isDebugging,
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
"Host": `localhost:${params.port}`
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
apiBase = new JsonApi({
|
apiBase = new JsonApi({
|
||||||
|
|||||||
@ -96,13 +96,14 @@ export interface IKubeApiCluster {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function forCluster<T extends KubeObject>(cluster: IKubeApiCluster, kubeClass: KubeObjectConstructor<T>): KubeApi<T> {
|
export function forCluster<T extends KubeObject>(cluster: IKubeApiCluster, kubeClass: KubeObjectConstructor<T>): KubeApi<T> {
|
||||||
|
const url = new URL(apiBase.config.serverAddress);
|
||||||
const request = new KubeJsonApi({
|
const request = new KubeJsonApi({
|
||||||
serverAddress: apiBase.config.serverAddress,
|
serverAddress: apiBase.config.serverAddress,
|
||||||
apiBase: apiKubePrefix,
|
apiBase: apiKubePrefix,
|
||||||
debug: isDevelopment,
|
debug: isDevelopment,
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
"Host": apiBase.config.serverAddress
|
"Host": `${cluster.metadata.uid}.localhost:${url.port}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import logger from "./logger";
|
|||||||
import { Singleton } from "../common/utils";
|
import { Singleton } from "../common/utils";
|
||||||
import type { Cluster } from "./cluster";
|
import type { Cluster } from "./cluster";
|
||||||
import type { ProxyApiRequestArgs } from "./proxy-functions";
|
import type { ProxyApiRequestArgs } from "./proxy-functions";
|
||||||
|
import { appEventBus } from "../common/event-bus";
|
||||||
|
|
||||||
type GetClusterForRequest = (req: http.IncomingMessage) => Cluster | null;
|
type GetClusterForRequest = (req: http.IncomingMessage) => Cluster | null;
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ export class LensProxy extends Singleton {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.port = port;
|
this.port = port;
|
||||||
process.env.LENS_PROXY_PORT = port.toString();
|
appEventBus.emit({ name: "lens-proxy", action: "listen", params: { port }});
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.once("error", (error) => {
|
.once("error", (error) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user