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.
 
 
 

34 lines
1.3 KiB

import {HTTPKernel} from '../HTTPKernel'
import {MountActivatedRouteHTTPModule} from './MountActivatedRouteHTTPModule'
import {Request} from '../../lifecycle/Request'
import {ActivatedRoute} from '../../routing/ActivatedRoute'
import {ResponseObject} from '../../routing/Route'
import {AbstractResolvedRouteHandlerHTTPModule} from './AbstractResolvedRouteHandlerHTTPModule'
/**
* HTTP Kernel module that executes the preflight handlers for the route.
*
* Usually, this is the pre middleware.
*/
export class ExecuteResolvedRoutePreflightHTTPModule extends AbstractResolvedRouteHandlerHTTPModule {
public static register(kernel: HTTPKernel): void {
kernel.register(this).after(MountActivatedRouteHTTPModule)
}
public async apply(request: Request): Promise<Request> {
if ( request.hasInstance(ActivatedRoute) ) {
const route = <ActivatedRoute> request.make(ActivatedRoute)
const preflight = route.preflight
for ( const handler of preflight ) {
const result: ResponseObject = await handler(request)
if ( typeof result !== 'undefined' ) {
await this.applyResponseObject(result, request)
request.response.blockingWriteback(true)
}
}
}
return request
}
}