Kirby Headless handles CORS preflight requests automatically, allowing your frontend application to fetch data from a different domain.
Customize CORS headers in your config.php:
return [
'headless' => [
'cors' => [
'allowOrigin' => '*',
'allowMethods' => 'GET, POST, OPTIONS',
'allowHeaders' => 'Accept, Content-Type, Authorization, X-Language, X-Cacheable',
'maxAge' => '86400'
]
]
];
allowOrigin StringSpecifies which origins can access your API. Use * to allow all origins, or specify a specific domain.
Default: *
allowMethods StringHTTP methods allowed for cross-origin requests.
Default: GET, POST, OPTIONS
allowHeaders StringHeaders that can be used in the actual request.
Default: Accept, Content-Type, Authorization, X-Language, X-Cacheable
maxAge StringHow long (in seconds) the preflight response can be cached.
Default: 86400 (24 hours)