24 lines
665 B
TypeScript
24 lines
665 B
TypeScript
export function corsHeaders() {
|
|
return {
|
|
"Access-Control-Allow-Origin": "*",
|
|
"Access-Control-Allow-Methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS",
|
|
"Access-Control-Allow-Headers":
|
|
"authorization, x-client-info, apikey, content-type, x-requested-with",
|
|
"Access-Control-Max-Age": "86400",
|
|
};
|
|
}
|
|
|
|
export function jsonResponse(data: any, status: number = 200) {
|
|
return new Response(JSON.stringify(data), {
|
|
status,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
...corsHeaders(),
|
|
},
|
|
});
|
|
}
|
|
|
|
export function errorResponse(message: string, status: number = 500) {
|
|
return jsonResponse({ error: message }, status);
|
|
}
|