mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Making apiBase injectable
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ed073d6562
commit
2f57644801
5 files changed
+74
-34
No files matched your search
@@ -3,38 +3,15 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { JsonApi } from "./json-api";
|
||||
import { apiPrefix, isDebugging, isDevelopment } from "../vars";
|
||||
import { appEventBus } from "../app-event-bus/event-bus";
|
||||
import type { JsonApi } from "./json-api";
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
|
||||
export let apiBase: JsonApi;
|
||||
export const apiBaseInjectionToken = getInjectionToken<JsonApi>({
|
||||
id: "api-base-token",
|
||||
});
|
||||
|
||||
if (typeof window === "undefined") {
|
||||
appEventBus.addListener((event) => {
|
||||
if (event.name !== "lens-proxy" && event.action !== "listen") return;
|
||||
|
||||
const params = event.params as { port?: number };
|
||||
|
||||
if (!params.port) return;
|
||||
|
||||
apiBase = new JsonApi({
|
||||
serverAddress: `http://127.0.0.1:${params.port}`,
|
||||
apiBase: apiPrefix,
|
||||
debug: isDevelopment || isDebugging,
|
||||
}, {
|
||||
headers: {
|
||||
"Host": `localhost:${params.port}`,
|
||||
},
|
||||
});
|
||||
});
|
||||
} else {
|
||||
apiBase = new JsonApi({
|
||||
serverAddress: `http://127.0.0.1:${window.location.port}`,
|
||||
apiBase: apiPrefix,
|
||||
debug: isDevelopment || isDebugging,
|
||||
}, {
|
||||
headers: {
|
||||
"Host": window.location.host,
|
||||
},
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @deprecated switch to using apiBaseInjectionToken instead
|
||||
*/
|
||||
export const apiBase = asLegacyGlobalForExtensionApi(apiBaseInjectionToken);
|
||||
@@ -11,4 +11,7 @@ export const apiKubeInjectionToken = getInjectionToken<KubeJsonApi>({
|
||||
id: "api-kube-injection-token",
|
||||
});
|
||||
|
||||
/**
|
||||
* @deprecated Switch to using apiKubeInjectionToken instead
|
||||
*/
|
||||
export const apiKube = asLegacyGlobalForExtensionApi(apiKubeInjectionToken);
|
||||
Reference in new issue
Block a user