mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
f2528968e6
commit
683aed20a7
@ -48,7 +48,7 @@ if (typeof window === "undefined") {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
apiBase = new JsonApi({
|
apiBase = new JsonApi({
|
||||||
serverAddress: `http://localhost:${window.location.port}`,
|
serverAddress: `http://${window.location.host}`,
|
||||||
apiBase: apiPrefix,
|
apiBase: apiPrefix,
|
||||||
debug: isDevelopment || isDebugging,
|
debug: isDevelopment || isDebugging,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
// Base http-service / json-api class
|
// Base http-service / json-api class
|
||||||
|
|
||||||
|
import { randomBytes } from "crypto";
|
||||||
import { merge } from "lodash";
|
import { merge } from "lodash";
|
||||||
import nodeFetch, { Response as NodeResponse, RequestInit as NodeRequestInit } from "node-fetch";
|
import nodeFetch, { Response as NodeResponse, RequestInit as NodeRequestInit } from "node-fetch";
|
||||||
import { stringify } from "querystring";
|
import { stringify } from "querystring";
|
||||||
@ -83,8 +84,10 @@ export class JsonApi<D = JsonApiData, P extends JsonApiParams = JsonApiParams> {
|
|||||||
|
|
||||||
protected getRequestUrl(path: string, useSubdomain = false) {
|
protected getRequestUrl(path: string, useSubdomain = false) {
|
||||||
if (window) {
|
if (window) {
|
||||||
|
const subdomain = useSubdomain ? `${randomBytes(2).toString("hex")}.` : "";
|
||||||
|
const url = new URL(this.config.serverAddress);
|
||||||
|
|
||||||
return `${this.config.apiBase}${path}`;
|
return `${url.protocol}//${subdomain}${url.host}${this.config.apiBase}${path}`;
|
||||||
} else {
|
} else {
|
||||||
return `${this.config.serverAddress}${this.config.apiBase}${path}`;
|
return `${this.config.serverAddress}${this.config.apiBase}${path}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -185,15 +185,25 @@ export class LensProxy extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async handleRequest(req: http.IncomingMessage, res: http.ServerResponse) {
|
protected async handleRequest(req: http.IncomingMessage, res: http.ServerResponse) {
|
||||||
|
// allow to fetch apis in "clusterId.localhost:port" from "localhost:port"
|
||||||
|
// this should be safe because we have already validated cluster uuid
|
||||||
|
|
||||||
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
||||||
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type, X-Cluster-Id");
|
||||||
|
|
||||||
|
if (req.method === "OPTIONS") {
|
||||||
|
res.end();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const cluster = this.getClusterForRequest(req);
|
const cluster = this.getClusterForRequest(req);
|
||||||
|
|
||||||
if (cluster) {
|
if (cluster) {
|
||||||
const proxyTarget = await this.getProxyTarget(req, cluster.contextHandler);
|
const proxyTarget = await this.getProxyTarget(req, cluster.contextHandler);
|
||||||
|
|
||||||
if (proxyTarget) {
|
if (proxyTarget) {
|
||||||
// allow to fetch apis in "clusterId.localhost:port" from "localhost:port"
|
|
||||||
// this should be safe because we have already validated cluster uuid
|
|
||||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
||||||
|
|
||||||
return this.proxy.web(req, res, proxyTarget);
|
return this.proxy.web(req, res, proxyTarget);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user