Trouble getting CORS to work between CodeIgniter and React app
Turns out I needed to check if it was a preflight request on the server, and respond appropriately:
header('Access-Control-Allow-Origin: *');header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");$method = $_SERVER['REQUEST_METHOD'];if($method == "OPTIONS") { die();}
Then I can make normal requests using the api key in my header.