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:
parent
711516cccf
commit
afa9c10969
@ -44,6 +44,14 @@ export class Router {
|
|||||||
protected router = new Call.Router();
|
protected router = new Call.Router();
|
||||||
static rootPath = path.resolve(__static);
|
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> {
|
public async route(cluster: Cluster, req: http.IncomingMessage, res: http.ServerResponse): Promise<boolean> {
|
||||||
const url = new URL(req.url, "http://localhost");
|
const url = new URL(req.url, "http://localhost");
|
||||||
const path = url.pathname;
|
const path = url.pathname;
|
||||||
@ -81,12 +89,6 @@ export class Router {
|
|||||||
params,
|
params,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
addRoute = (route: Route) => {
|
|
||||||
this.router.add({ method: route.method, path: route.path }, (request: LensApiRequest) => {
|
|
||||||
route.handler(request);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Route {
|
export interface Route {
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import { Router, Route } from "../router";
|
import { Route, Router } from "../router";
|
||||||
|
|
||||||
export const routeInjectionToken = getInjectionToken<Route>({
|
export const routeInjectionToken = getInjectionToken<Route>({
|
||||||
id: "route-injection-token",
|
id: "route-injection-token",
|
||||||
@ -13,15 +13,9 @@ const routerInjectable = getInjectable({
|
|||||||
id: "router",
|
id: "router",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const router = new Router();
|
|
||||||
|
|
||||||
const routes = di.injectMany(routeInjectionToken);
|
const routes = di.injectMany(routeInjectionToken);
|
||||||
|
|
||||||
routes.forEach(route => {
|
return new Router(routes);
|
||||||
router.addRoute(route);
|
|
||||||
});
|
|
||||||
|
|
||||||
return router;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user