Skip to content

Commit

Permalink
refactor: rename beforeResponse to onBeforeResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 14, 2023
1 parent 3f9c8b6 commit 7cebec2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/event/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { H3Event } from "./event";

type _EventHandlerHooks = {
onRequest?: _RequestMiddleware[];
beforeResponse?: _ResponseMiddleware[];
onBeforeResponse?: _ResponseMiddleware[];
};

export function defineEventHandler<
Expand Down Expand Up @@ -51,7 +51,7 @@ export function defineEventHandler<
// Object Syntax
const _hooks: _EventHandlerHooks = {
onRequest: _normalizeArray(handler.onRequest),
beforeResponse: _normalizeArray(handler.beforeResponse),
onBeforeResponse: _normalizeArray(handler.onBeforeResponse),
};
const _handler: EventHandler<Request, any> = (event) => {
return _callHandler(event, handler.handler, _hooks);
Expand All @@ -78,8 +78,8 @@ async function _callHandler(
}
const body = await handler(event);
const response = { body };
if (hooks.beforeResponse) {
for (const hook of hooks.beforeResponse) {
if (hooks.onBeforeResponse) {
for (const hook of hooks.onBeforeResponse) {
await hook(event, response);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export type EventHandlerObject<
Response extends EventHandlerResponse = EventHandlerResponse,
> = {
onRequest?: _RequestMiddleware<Request> | _RequestMiddleware<Request>[];
beforeResponse?:
onBeforeResponse?:
| _ResponseMiddleware<Request, Response>
| _ResponseMiddleware<Request, Response>[];
handler: EventHandler<Request, Response>;
Expand Down

0 comments on commit 7cebec2

Please sign in to comment.