Add CORS headers to fix 403

This commit is contained in:
Web-serfer 2026-04-27 20:55:33 +05:00
parent 7365ff107c
commit 4f6d82bc7b
2 changed files with 37 additions and 17 deletions

View file

@ -1,6 +1,17 @@
import type { APIRoute } from 'astro';
export const POST: APIRoute = async ({ request, url }) => {
if (request.method === 'OPTIONS') {
return new Response(null, {
status: 204,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
}
});
}
const params = Object.fromEntries(url.searchParams.entries());
return new Response(JSON.stringify({
@ -9,6 +20,9 @@ export const POST: APIRoute = async ({ request, url }) => {
url: request.url,
}), {
status: 200,
headers: { 'Content-Type': 'application/json' }
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
}
});
};