CORS Handler


This middleware will help you set your CORS options and it is based on built in H3 CORS functionality

This middleware will help you solve this security problem.

export interface H3CorsOptions {    origin?: '*' | 'null' | (string | RegExp)[] | ((origin: string) => boolean);    methods?: '*' | HTTPMethod[];    allowHeaders?: '*' | string[];    exposeHeaders?: '*' | string[];    credentials?: boolean;    maxAge?: string | false;    preflight?: {        statusCode?: number;    };}

To write a custom logic for this middleware follow this pattern:

nuxt.config.ts
export default defineNuxtConfig({  security: {    corsHandler: {      origin: '*',      methods: '*',    }  }})

Or use routeRules for per route configuration:

nuxt.config.ts
export default defineNuxtConfig({  routeRules: {    '/my-secret-route': {      security: {        corsHandler: {          origin: '*',          methods: '*',        }      }    }  }