Standard libraries that lift up your code.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.4 KiB

import {Injectable, Inject} from '../../../di'
import {HTTPKernelModule} from '../HTTPKernelModule'
import {HTTPKernel} from '../HTTPKernel'
import {Request} from '../../lifecycle/Request'
import {Routing} from '../../../service/Routing'
import {ActivatedRoute} from '../../routing/ActivatedRoute'
import {Logging} from '../../../service/Logging'
* HTTP kernel middleware that tries to find a registered route matching the request's
* path and creates an ActivatedRoute instance from it.
export class MountActivatedRouteHTTPModule extends HTTPKernelModule {
public readonly executeWithBlockingWriteback = true
protected readonly routing!: Routing
protected readonly logging!: Logging
public static register(kernel: HTTPKernel): void {
public async apply(request: Request): Promise<Request> {
const route = this.routing.match(request.method, request.path)
if ( route ) {
this.logging.verbose(`Mounting activated route: ${request.path} -> ${route}`)
const activated = <ActivatedRoute> request.make(ActivatedRoute, route, request.path)
request.registerSingletonInstance<ActivatedRoute>(ActivatedRoute, activated)
} else {
this.logging.debug(`No matching route found for: ${request.method} -> ${request.path}`)
return request