1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/main/start-main-application/runnables/lens-proxy/request-app-version.injectable.ts
Sebastian Malton 4c1d07693f Add process of cleaning up lens proxy startup if down quickly
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2023-01-10 15:18:11 -05:00

37 lines
1.1 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 lensFetchInjectable from "../../../../common/fetch/lens-fetch.injectable";
import type { AbortSignal as NonStandardAbortSignal } from "abort-controller";
export interface RequestOptions {
signal: AbortSignal;
}
export type RequestAppVersionViaProxy = (options: RequestOptions) => Promise<string>;
const requestAppVersionViaProxyInjectable = getInjectable({
id: "request-app-version-via-proxy",
instantiate: (di): RequestAppVersionViaProxy => {
const lensFetch = di.inject(lensFetchInjectable);
return async (options) => {
const response = await lensFetch("/version", {
signal: options.signal as NonStandardAbortSignal,
});
if (response.status !== 200) {
throw new Error(`Retrieving version failed: ${response.statusText}`);
}
const body = await response.json() as { version: string };
return body.version;
};
},
});
export default requestAppVersionViaProxyInjectable;