diff --git a/src/common/k8s-api/index.ts b/src/common/k8s-api/index.ts index 1c0f32e0f2..e1865f3d52 100644 --- a/src/common/k8s-api/index.ts +++ b/src/common/k8s-api/index.ts @@ -56,7 +56,7 @@ if (typeof window === "undefined") { if (isClusterPageContext()) { apiKube = new KubeJsonApi({ - serverAddress: `http://${window.location.host}:${window.location.port}`, + serverAddress: `http://${window.location.host}`, apiBase: apiKubePrefix, debug: isDevelopment }); diff --git a/src/common/k8s-api/json-api.ts b/src/common/k8s-api/json-api.ts index 00dc35cef2..9f59ba9e6c 100644 --- a/src/common/k8s-api/json-api.ts +++ b/src/common/k8s-api/json-api.ts @@ -21,7 +21,6 @@ // Base http-service / json-api class -import { randomBytes } from "crypto"; import { merge } from "lodash"; import nodeFetch, { Response as NodeResponse, RequestInit as NodeRequestInit } from "node-fetch"; import { stringify } from "querystring"; @@ -82,8 +81,17 @@ export class JsonApi { return this.request(path, params, { ...reqInit, method: "get" }); } + protected getRequestUrl(path: string, useSubdomain = false) { + if (window) { + + return `${this.config.apiBase}${path}`; + } else { + return `${this.config.serverAddress}${this.config.apiBase}${path}`; + } + } + getResponse(path: string, params?: P, init: JsonRequestInit = {}): Promise { - let reqUrl = this.buildRequestUrl(path, true); + let reqUrl = this.getRequestUrl(path, true); const reqInit = merge({}, this.reqInit, init); const { query } = params || {} as P; @@ -120,18 +128,8 @@ export class JsonApi { return this.request(path, params, { ...reqInit, method: "delete" }); } - protected buildRequestUrl(path: string, useSubdomain = false) { - if (window) { - const subdomain = useSubdomain ? `${randomBytes(2).toString("hex")}.` : ""; - - return `http://${subdomain}${window.location.host}${this.config.apiBase}${path}`; - } else { - return `${this.config.serverAddress}${this.config.apiBase}${path}`; - } - } - protected async request(path: string, params?: P, init: JsonRequestInit = {}) { - let reqUrl = this.buildRequestUrl(path); + let reqUrl = this.getRequestUrl(path); const reqInit = merge({}, this.reqInit, init); const { data, query } = params || {} as P;