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.
lib/src/http/routing/ActivatedRoute.ts

30 lines
956 B

import {ErrorWithContext} from "@extollo/util";
import {ResolvedRouteHandler, Route} from "./Route";
export class ActivatedRoute {
public readonly params: {[key: string]: string}
public readonly handler: ResolvedRouteHandler
public readonly preflight: ResolvedRouteHandler[]
public readonly postflight: ResolvedRouteHandler[]
constructor(
public readonly route: Route,
public readonly path: string
) {
const params = route.extract(path)
if ( !params ) {
const error = new ErrorWithContext('Cannot get params for route. Path does not match.')
error.context = {
matchedRoute: String(route),
requestPath: path,
}
throw error
}
this.params = params
this.preflight = route.resolvePreflight()
this.handler = route.resolveHandler()
this.postflight = route.resolvePostflight()
}
}