export function definePostEventHandler<TInput, TOutput>(
input: (rawBody: unknown) => TInput,
handler: (body: TInput, event: H3Event<EventHandlerRequest>) => Promise<TOutput>,
): EventHandler<EventHandlerRequest, Promise<[TOutput, TInput]>> {
return defineEventHandler(async (event) => {
return [handler(input(readBody(event)), event)] as any;
});
}
// If you don't want input validation
definePostEventHandler.any = <T>(rawBody: unknown) => rawBody as T;
export function definePostEventHandler<TInput, TOutput>(
input: (rawBody: unknown) => TInput,
handler: (body: TInput, event: H3Event<EventHandlerRequest>) => Promise<TOutput>,
): EventHandler<EventHandlerRequest, Promise<[TOutput, TInput]>> {
return defineEventHandler(async (event) => {
return [handler(input(readBody(event)), event)] as any;
});
}
// If you don't want input validation
definePostEventHandler.any = <T>(rawBody: unknown) => rawBody as T;