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

Introduce and use windowLocationInjectable

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-08-12 09:31:11 -04:00
parent fd19280065
commit c3c736c065
3 changed files with 25 additions and 4 deletions

View File

@ -0,0 +1,17 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
const windowLocationInjectable = getInjectable({
id: "window-location",
instantiate: () => {
const { host, port } = window.location;
return { host, port };
},
causesSideEffects: true,
});
export default windowLocationInjectable;

View File

@ -5,6 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import { apiBaseInjectionToken } from "../../common/k8s-api/api-base";
import createJsonApiInjectable from "../../common/k8s-api/create-json-api.injectable";
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
import { apiPrefix } from "../../common/vars";
import isDebuggingInjectable from "../../common/vars/is-debugging.injectable";
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
@ -14,16 +15,17 @@ const apiBaseInjectable = getInjectable({
instantiate: (di) => {
const createJsonApi = di.inject(createJsonApiInjectable);
const isDebugging = di.inject(isDebuggingInjectable);
const { port, host } = di.inject(windowLocationInjectable);
return createJsonApi(
{
serverAddress: `http://127.0.0.1:${window.location.port}`,
serverAddress: `http://127.0.0.1:${port}`,
apiBase: apiPrefix,
debug: di.inject(isDevelopmentInjectable) || isDebugging,
},
{
headers: {
"Host": window.location.host,
"Host": host,
},
},
);

View File

@ -10,6 +10,7 @@ import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/st
import createKubeJsonApiInjectable from "../../common/k8s-api/create-kube-json-api.injectable";
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
import showErrorNotificationInjectable from "../components/notifications/show-error-notification.injectable";
import windowLocationInjectable from "../../common/k8s-api/window-location.injectable";
const apiKubeInjectable = getInjectable({
id: "api-kube",
@ -18,14 +19,15 @@ const apiKubeInjectable = getInjectable({
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
const isDevelopment = di.inject(isDevelopmentInjectable);
const showErrorNotification = di.inject(showErrorNotificationInjectable);
const { port, host } = di.inject(windowLocationInjectable);
const apiKube = createKubeJsonApi({
serverAddress: `http://127.0.0.1:${window.location.port}`,
serverAddress: `http://127.0.0.1:${port}`,
apiBase: apiKubePrefix,
debug: isDevelopment,
}, {
headers: {
"Host": window.location.host,
"Host": host,
},
});