Roadbound-BRR/supabase/functions/_shared/http.ts

24 lines
705 B
TypeScript

export const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
};
export function json(data: unknown, status = 200): Response {
return new Response(JSON.stringify(data), {
status,
headers: {
...corsHeaders,
"Content-Type": "application/json",
},
});
}
export function fail(message: string, status = 400): Response {
return json({ error: message }, status);
}
export function handleOptions(req: Request): Response | null {
if (req.method !== "OPTIONS") return null;
return new Response("ok", { headers: corsHeaders });
}