Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
routes: Route[],
params: Map): Route | undefined {
const rpaths = [];
// find matching route, fabricating if necessary
let route = this.matchImpl(paths, rpaths, method, parent, routes, params);
// we always need a handler
if (!route.handler) {
if (route.children)
route.handler = NotFound;
else route.handler = route.redirectTo? RedirectTo : StatusCode200;
}
// create an injector
if (!route.injector) {
const providers = (route.services || []).concat(route.middlewares || []);
providers.push(route.handler);
const resolved = ReflectiveInjector.resolve(providers);
if (parent)
route.injector = parent.injector.createChildFromResolved(resolved);
else route.injector = ReflectiveInjector.fromResolvedProviders(resolved);
}
// look to the children
if (route.children && (paths.length > rpaths.length))
route = this.match(paths.slice(rpaths.length), method, route, route.children, params);
return route;
}
return await Promise.all(this.providers).then(async (providers) => {
const resolvedProviders = ReflectiveInjector.resolve(CORE_PROVIDERS(this.options).concat(providers));
const injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders);
const dispatcher = injector.get(AsyncEventDispatcher);
resolvedProviders.forEach((provider: ResolvedReflectiveProvider) => {
const service = injector.get(provider.key.token);
this.resolveInjectorAwareService(service, injector);
this.resolveEventListeners(service, dispatcher);
});
const bootstrapEvent = new BootstrapEvent(injector, resolvedProviders);
await dispatcher.dispatch(ApplicationEvents.BOOTSTRAP, bootstrapEvent);
injector.get(Kernel).initialize();
return injector;
});
}