NuxtN
Nuxt2y ago
cosbgn

Did anyone manage to handle CORS with h3/nuxt/nitro?

I'm trying everything like this:

export default defineEventHandler( async (event) => {
    const cors_headers = { 
        origin: '*', 
        preflight: { statusCode: 204 }, 
        methods: '*' 
    }
    await handleCors(event, cors_headers)
    await appendCorsHeaders(event, cors_headers)
    await appendResponseHeaders(event, {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "GET, HEAD, POST, OPTIONS",
        "Access-Control-Allow-Headers": "*"
    })
return "hello"
 })


I always get: request blocked: (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Was this page helpful?