Hooks
Hooks are executed before and after the request handler is executed.
Pre Hooks
Post Hooks
# Execute the built-in Deno task
deno task create:module -t hook -n checkPermission --template blank.tsimport {
type IRequestContext,
type RawResponse,
type Response,
} from "@Core/common/mod.ts";
import { type RouterContext } from "oak";
export default {
// This function is executed when a request is received from the client
// and it passes all the middlewares.
pre: (
// scope is the name of the controller to which the request is hitting.
scope: string,
// name refers to the name of the request handler endpoint.
name: string,
ctx: IRequestContext<RouterContext<string>>
) => {
console.info(
"We are going to execute the following scope.permission:",
`${scope}.${name}`
);
},
// This function is executed after the request handler has been executed
// and the server is about the send the response to the client.
post: (
scope: string,
name: string,
detail: {
ctx: IRequestContext<RouterContext<string>>;
res: RawResponse | Response;
}
) => {
console.info(
"We have executed the following scope.permission:",
`${scope}.${name}`
);
},
};
Last updated