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.
41 lines
1.0 KiB
41 lines
1.0 KiB
import {Collection} from "@extollo/util"
|
|
import {AppClass} from "../../lifecycle/AppClass"
|
|
import {RouteHandler} from "./Route"
|
|
|
|
export class RouteGroup extends AppClass {
|
|
private static currentGroupNesting: RouteGroup[] = []
|
|
|
|
protected middlewares: Collection<{ stage: 'pre' | 'post', handler: RouteHandler }> = new Collection<{stage: "pre" | "post"; handler: RouteHandler}>()
|
|
|
|
public static getCurrentGroupHierarchy(): RouteGroup[] {
|
|
return [...this.currentGroupNesting]
|
|
}
|
|
|
|
constructor(
|
|
public readonly group: () => void | Promise<void>,
|
|
public readonly prefix: string
|
|
) { super() }
|
|
|
|
pre(middleware: RouteHandler) {
|
|
this.middlewares.push({
|
|
stage: 'pre',
|
|
handler: middleware
|
|
})
|
|
|
|
return this
|
|
}
|
|
|
|
post(middleware: RouteHandler) {
|
|
this.middlewares.push({
|
|
stage: 'post',
|
|
handler: middleware,
|
|
})
|
|
|
|
return this
|
|
}
|
|
|
|
getGroupMiddlewareDefinitions() {
|
|
return this.middlewares
|
|
}
|
|
}
|