Set up CORS
← All configuration scenariosConfigure the origin
If a frontend at https://app.example.com calls your API from a different origin, the browser may send a preflight before the real request. By default cors.headers is empty and your application handles it. Add this block to your profile to have the server handle the preflight.
{
"listen": { "port": 9000 },
"cors": {
"headers": {
"Access-Control-Allow-Origin": ["https://app.example.com"],
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type"
}
}
}Save the example as cors.json in the application root and start the bundled handler.
php vendor/mini4work/webserver/examples/server.php cors.jsonSend the preflight
In a second terminal, simulate the browser request.
curl -i -X OPTIONS http://127.0.0.1:9000/ \
-H 'Origin: https://app.example.com' \
-H 'Access-Control-Request-Method: POST'Expect 204 with an empty body and the matching allow-origin header. In list mode the origin must match exactly, including scheme and port. Other origins do not receive that header. An ordinary OPTIONS request without the two preflight headers goes to PHP.