CORS when Axios with Bearer Token token using Codeigniter4 and Vue Vite
Sep 16, 2023
Response to preflight request doesn’t pass access control check ……OMG
Modify File Location: Public/index.php
Edit Code:
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();
}
- > Change
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Authorization");
or
header("Access-Control-Allow-Headers: *");
My 5 hours Spent Result!