mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix faking lensFetch
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
aea545526d
commit
fdae7870da
10 files changed
+73
-68
No files matched your search
@@ -13,7 +13,7 @@ export default getGlobalOverride(lensProxyInjectable, (di) => {
|
||||
return ({
|
||||
close: () => { },
|
||||
listen: async () => {
|
||||
lensProxyPort.set(12345);
|
||||
lensProxyPort.set(23456);
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { DiContainerForInjection, Injectable, InjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Injectable, InjectionToken } from "@ogre-tools/injectable";
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Route, LensApiRequest } from "./route";
|
||||
import createHandlerForRouteInjectable from "./create-handler-for-route.injectable";
|
||||
@@ -27,22 +27,16 @@ export function getRouteInjectable<T, Path extends string>(
|
||||
|
||||
export type RouteRequest = (cluster: Cluster | undefined, req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
|
||||
|
||||
const createRouter = (di: DiContainerForInjection) => {
|
||||
const routes = di.injectMany(routeInjectionToken);
|
||||
const createHandlerForRoute = di.inject(createHandlerForRouteInjectable);
|
||||
const router = new Call.Router<RouteHandler>();
|
||||
|
||||
for (const route of routes) {
|
||||
router.add({ method: route.method, path: route.path }, createHandlerForRoute(route));
|
||||
}
|
||||
|
||||
return router;
|
||||
};
|
||||
|
||||
const routeRequestInjectable = getInjectable({
|
||||
id: "route-request",
|
||||
instantiate: (di): RouteRequest => {
|
||||
const router = createRouter(di);
|
||||
const routes = di.injectMany(routeInjectionToken);
|
||||
const createHandlerForRoute = di.inject(createHandlerForRouteInjectable);
|
||||
const router = new Call.Router<RouteHandler>();
|
||||
|
||||
for (const route of routes) {
|
||||
router.add({ method: route.method, path: route.path }, createHandlerForRoute(route));
|
||||
}
|
||||
|
||||
return async (cluster, req, res) => {
|
||||
if (!req.url || !req.method) {
|
||||
@@ -50,7 +44,7 @@ const routeRequestInjectable = getInjectable({
|
||||
}
|
||||
|
||||
const url = new URL(req.url, "https://localhost");
|
||||
const matchingRoute = router.route(req.method, url.pathname);
|
||||
const matchingRoute = router.route(req.method?.toLowerCase() ?? "get", url.pathname);
|
||||
|
||||
if (matchingRoute instanceof Error) {
|
||||
return false;
|
||||
|
||||
@@ -8,10 +8,8 @@ import { object } from "../../common/utils";
|
||||
|
||||
export interface LensServerResponse {
|
||||
statusCode: number;
|
||||
content: any;
|
||||
headers: {
|
||||
[name: string]: string;
|
||||
};
|
||||
content: unknown;
|
||||
headers: Partial<Record<string, string | string[]>>;
|
||||
}
|
||||
|
||||
export const writeServerResponseFor = (serverResponse: ServerResponse) => ({
|
||||
|
||||
@@ -31,8 +31,10 @@ const setupLensProxyInjectable = getInjectable({
|
||||
try {
|
||||
logger.info("🔌 Starting LensProxy");
|
||||
await lensProxy.listen(); // lensProxy.port available
|
||||
} catch (error: any) {
|
||||
showErrorPopup("Lens Error", `Could not start proxy: ${error?.message || "unknown error"}`);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "unknown error";
|
||||
|
||||
showErrorPopup("Lens Error", `Could not start proxy: ${message}`);
|
||||
|
||||
return exitApp();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user