atelier/ts/responses.ts
2025-02-02 12:24:00 -05:00

14 lines
462 B
TypeScript

export type Body = ConstructorParameters<typeof Response>[0];
export type ResponseOptions = ConstructorParameters<typeof Response>[1];
export function badRequest(body?: Body, options?: ResponseOptions): Response {
return new Response(body, { status: 400, ...options });
}
export function html(body: Body, options?: ResponseOptions): Response {
return new Response(body, {
...options,
headers: { 'Content-Type': 'text/html', ...options?.headers },
});
}