Add mounting for activated routes, route compiling, routing
This commit is contained in:
23
src/http/routing/ActivatedRoute.ts
Normal file
23
src/http/routing/ActivatedRoute.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {ErrorWithContext} from "@extollo/util";
|
||||
import {Route} from "./Route";
|
||||
|
||||
export class ActivatedRoute {
|
||||
public readonly params: {[key: string]: string}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user