1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/core/src/common/fetch/lens-fetch.injectable.ts
Jari Kolehmainen 7e8ae3fded
Move node-fetch to separate package (#7009)
* move node-fetch to separate package

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix node-fetch package runtime error

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix test:unit nx dependency

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix test:unit nx dependency

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* Add prepare step for node-fetch

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Update lock

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Remove dead comment

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Remove unnecessary fetchModuleInjectable

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Co-authored-by: Sebastian Malton <sebastian@malton.name>
2023-01-25 17:13:41 +02:00

37 lines
1.2 KiB
TypeScript

/**
* 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 "@k8slens/node-fetch";
import lensProxyPortInjectable from "../../main/lens-proxy/lens-proxy-port.injectable";
import lensProxyCertificateInjectable from "../certificate/lens-proxy-certificate.injectable";
import fetch from "@k8slens/node-fetch";
export type LensRequestInit = Omit<RequestInit, "agent">;
export type LensFetch = (pathnameAndQuery: string, init?: LensRequestInit) => Promise<Response>;
const lensFetchInjectable = getInjectable({
id: "lens-fetch",
instantiate: (di): LensFetch => {
const lensProxyPort = di.inject(lensProxyPortInjectable);
const lensProxyCertificate = di.inject(lensProxyCertificateInjectable);
return async (pathnameAndQuery, init = {}) => {
const agent = new Agent({
ca: lensProxyCertificate.get().cert,
});
return fetch(`https://127.0.0.1:${lensProxyPort.get()}${pathnameAndQuery}`, {
...init,
agent,
});
};
},
causesSideEffects: true,
});
export default lensFetchInjectable;