mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Replace usage of request in setupLensProxy
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
c3402562a1
commit
f522d23662
4 files changed
+65
-24
No files matched your search
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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";
|
||||
import { Agent } from "https";
|
||||
import type { RequestInit, Response } from "node-fetch";
|
||||
import lensProxyPortInjectable from "../../main/lens-proxy/lens-proxy-port.injectable";
|
||||
import lensProxyCertificateInjectable from "../certificate/lens-proxy-certificate.injectable";
|
||||
import nodeFetchModuleInjectable from "./fetch-module.injectable";
|
||||
|
||||
export type LensFetch = (pathnameAndOrQuery: string, init?: Omit<RequestInit, "agent">) => Promise<Response>;
|
||||
|
||||
/**
|
||||
* This fetch is for requesting items from the Lens Proxy and thus does not cause side effects
|
||||
*/
|
||||
const lensFetchInjectable = getInjectable({
|
||||
id: "lens-fetch",
|
||||
instantiate: (di): LensFetch => {
|
||||
const { default: fetch } = di.inject(nodeFetchModuleInjectable);
|
||||
const lensProxyPort = di.inject(lensProxyPortInjectable);
|
||||
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
|
||||
|
||||
return async (pathnameAndOrQuery, init) => fetch(`https://127.0.0.1:${lensProxyPort.get()}${pathnameAndOrQuery}`, {
|
||||
...init,
|
||||
agent: new Agent({
|
||||
ca: lensProxyCertificate.get().cert,
|
||||
}),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default lensFetchInjectable;
|
||||
@@ -7,7 +7,7 @@ import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import { SemVer } from "semver";
|
||||
import type { InitializableState } from "../initializable-state/create";
|
||||
import { createInitializableState } from "../initializable-state/create";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel";
|
||||
|
||||
export const buildVersionInjectionToken = getInjectionToken<InitializableState<string>>({
|
||||
id: "build-version-token",
|
||||
|
||||
Reference in new issue
Block a user