1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Make adding routes private for router

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-02-11 12:47:16 +02:00
parent 711516cccf
commit afa9c10969
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
2 changed files with 10 additions and 14 deletions

View File

@ -44,6 +44,14 @@ export class Router {
protected router = new Call.Router();
static rootPath = path.resolve(__static);
constructor(routes: Route[]) {
routes.forEach(route => {
this.router.add({ method: route.method, path: route.path }, (request: LensApiRequest) => {
route.handler(request);
});
});
}
public async route(cluster: Cluster, req: http.IncomingMessage, res: http.ServerResponse): Promise<boolean> {
const url = new URL(req.url, "http://localhost");
const path = url.pathname;
@ -81,12 +89,6 @@ export class Router {
params,
};
}
addRoute = (route: Route) => {
this.router.add({ method: route.method, path: route.path }, (request: LensApiRequest) => {
route.handler(request);
});
};
}
export interface Route {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
import { Router, Route } from "../router";
import { Route, Router } from "../router";
export const routeInjectionToken = getInjectionToken<Route>({
id: "route-injection-token",
@ -13,15 +13,9 @@ const routerInjectable = getInjectable({
id: "router",
instantiate: (di) => {
const router = new Router();
const routes = di.injectMany(routeInjectionToken);
routes.forEach(route => {
router.addRoute(route);
});
return router;
return new Router(routes);
},
});