diff --git a/docs/2.guide/2.directory-structure/1.server.md b/docs/2.guide/2.directory-structure/1.server.md index f2a5947f2a..8efcf53bb0 100644 --- a/docs/2.guide/2.directory-structure/1.server.md +++ b/docs/2.guide/2.directory-structure/1.server.md @@ -102,6 +102,27 @@ Server routes are powered by [unjs/h3](https://github.com/unjs/h3) which comes w You can add more helpers yourself inside the `~/server/utils` directory. +For example, you can define a custom handler utility that wraps the original handler and performs additional operations before returning the final response. + +**Example:** + +```ts [server/utils/handler.ts] +import type { EventHandler } from 'h3' + +export const defineWrappedResponseHandler = (handler: EventHandler) => + defineEventHandler(async (event) => { + try { + // do something before the route handler + const response = await handler(event) + // do something after the route handler + return { response } + } catch (err) { + // Error handling + return { err } + } + }) +``` + ## Server Types ::alert{type="info"}