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.
34 lines
1.2 KiB
34 lines
1.2 KiB
3 years ago
|
import {Injectable, Inject} from "@extollo/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";
|
||
|
|
||
|
@Injectable()
|
||
|
export class MountActivatedRouteHTTPModule extends HTTPKernelModule {
|
||
|
@Inject()
|
||
|
protected readonly routing!: Routing
|
||
|
|
||
|
@Inject()
|
||
|
protected readonly logging!: Logging
|
||
|
|
||
|
public static register(kernel: HTTPKernel) {
|
||
|
kernel.register(this).before()
|
||
|
}
|
||
|
|
||
|
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 = new ActivatedRoute(route, request.path)
|
||
|
request.registerSingletonInstance<ActivatedRoute>(ActivatedRoute, activated)
|
||
|
} else {
|
||
|
this.logging.debug(`No matching route found for: ${request.method} -> ${request.path}`)
|
||
|
}
|
||
|
|
||
|
return request
|
||
|
}
|
||
|
}
|