-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
enhancementNew feature or requestNew feature or request
Description
It would be good to support some form of middleware to allow processing of requests/responses in a more general fashion. Hapi uses the following (with some extra overloads):
type ExtPoint = "onPreStart" | "onPostStart" | "onPreStop" | "onPostStop"
| "onRequest" | "onPreAuth" | "onCredentials" | "onPostAuth" | "onPreHandler"
| "onPostHandler" | "onPreResponse" | "onPostResponse";
interface ExtOptions {
before?: string | string[];
after?: string | string[];
bind?: object;
sandbox?: string;
timeout?: number;
}
interface ExtEvent {
type: ExtPoint;
method(request: Request, h: Toolkit): void;
options?: ExtOptions
}
interface Server {
ext(events: ExtEvent | ExtEvent[]): void;
ext(
event: ExtPoint,
method?: (request: Request, h: Toolkit) => void,
options?: ExtOptions,
): void;
}A suggestion I had was to use a modified version, which uses class instances for each request. That way you can keep track of information during a request (such as timing), and allows for an API like so:
interface ExtHandler {
onPreStart?(request: Request): void;
onPostStart?(request: Request): void;
onPreStop?(request: Request): void;
onPostStop?(request: Request): void;
onRequest?(request: Request): void;
onPreAuth?(request: Request): void;
onCredentials?(request: Request): void;
onPostAuth?(request: Request): void;
onPreHandler?(request: Request): void;
onPostHandler?(request: Request, response: Response): void;
onPreResponse?(request: Request, response: Response): void;
onPostResponse?(request: Request, response: Response): void;
}
interface Server {
ext(handler: new (h: Toolkit) => ExtHandler): void;
}It should be possible to support both, but that would complicate things possibly. Another option would be to support
interface Server {
ext(handler: ExtHandler): void;
}in some way to allow for the case where you don't need to store instance data (if this was supported, each method would also get h as well).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request