Skip to content

Commit 7cebec2

Browse files
committedAug 14, 2023
refactor: rename beforeResponse to onBeforeResponse
1 parent 3f9c8b6 commit 7cebec2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed
 

‎src/event/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { H3Event } from "./event";
1111

1212
type _EventHandlerHooks = {
1313
onRequest?: _RequestMiddleware[];
14-
beforeResponse?: _ResponseMiddleware[];
14+
onBeforeResponse?: _ResponseMiddleware[];
1515
};
1616

1717
export function defineEventHandler<
@@ -51,7 +51,7 @@ export function defineEventHandler<
5151
// Object Syntax
5252
const _hooks: _EventHandlerHooks = {
5353
onRequest: _normalizeArray(handler.onRequest),
54-
beforeResponse: _normalizeArray(handler.beforeResponse),
54+
onBeforeResponse: _normalizeArray(handler.onBeforeResponse),
5555
};
5656
const _handler: EventHandler<Request, any> = (event) => {
5757
return _callHandler(event, handler.handler, _hooks);
@@ -78,8 +78,8 @@ async function _callHandler(
7878
}
7979
const body = await handler(event);
8080
const response = { body };
81-
if (hooks.beforeResponse) {
82-
for (const hook of hooks.beforeResponse) {
81+
if (hooks.onBeforeResponse) {
82+
for (const hook of hooks.onBeforeResponse) {
8383
await hook(event, response);
8484
}
8585
}

‎src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export type EventHandlerObject<
8888
Response extends EventHandlerResponse = EventHandlerResponse,
8989
> = {
9090
onRequest?: _RequestMiddleware<Request> | _RequestMiddleware<Request>[];
91-
beforeResponse?:
91+
onBeforeResponse?:
9292
| _ResponseMiddleware<Request, Response>
9393
| _ResponseMiddleware<Request, Response>[];
9494
handler: EventHandler<Request, Response>;

0 commit comments

Comments
 (0)
Please sign in to comment.