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:
parent
fd19280065
commit
c3c736c065
17
src/common/k8s-api/window-location.injectable.ts
Normal file
17
src/common/k8s-api/window-location.injectable.ts
Normal 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;
|
||||
@ -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,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user