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

reverted cluster-manager.ts/getClusterForRequest()

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-08-12 20:07:15 +03:00
parent 2e9bb3e926
commit 75e4aa0a89

View File

@ -4,6 +4,7 @@ import { autorun } from "mobx";
import { ClusterId, clusterStore } from "../common/cluster-store"
import { Cluster } from "./cluster"
import logger from "./logger";
import { apiKubePrefix } from "../common/vars";
export class ClusterManager {
constructor(public readonly port: number) {
@ -42,8 +43,23 @@ export class ClusterManager {
}
getClusterForRequest(req: http.IncomingMessage): Cluster {
logger.debug(`getClusterForRequest(): ${req.headers.host}${req.url}`)
const clusterId = req.headers.host.split(".")[0]
return this.getCluster(clusterId)
let cluster: Cluster = null
// lens-server is connecting to 127.0.0.1:<port>/<uid>
if (req.headers.host.startsWith("127.0.0.1")) {
const clusterId = req.url.split("/")[1]
if (clusterId) {
cluster = this.getCluster(clusterId)
if (cluster) {
// we need to swap path prefix so that request is proxied to kube api
req.url = req.url.replace(`/${clusterId}`, apiKubePrefix)
}
}
} else {
const id = req.headers.host.split(".")[0]
cluster = this.getCluster(id)
}
return cluster;
}
}