I have a project that is currently using Vue cli on localhost:8080 then it request to my laravel api at api.sched.local but it gives me a error CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I'm using laravel 8 so it has already a config/cors and this is inside it
return [
/*
|--------------------------------------------------------------------------
| Cross-Origin Resource Sharing (CORS) Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your settings for cross-origin resource sharing
| or "CORS". This determines what cross-origin operations may execute
| in web browsers. You are free to adjust these settings as needed.
|
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
*/
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
and on my axios instance
import axios from 'axios'
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
axios.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded'
axios.defaults.headers.post['Content-Type'] ='application/json;charset=utf-8';
axios.defaults.headers.common['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
const defaultOptions = {
headers: {},
}
// var isDevelopment = true;
const instance = axios.create(defaultOptions);
export default instance
I've been stuck on this CORS error for 2 days thanks
NOTE: I am also using laravel passport I dont know if this affect something