User flow
- On my homepage I want the user to insert their License Plate.
- The License Plate number will make a request in the API domain
- I will get the details back for the Car which has the License Plate
Issue
- The API won't accept my request, I get the console error:
has been blocked by CORS policy: Request header field x-csrf-token is not allowed by Access-Control-Allow-Headers in preflight response.
Installed package for CORS
- I have installed the barryvdh/laravel-cors package
config/cors.php
return [
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedOriginsPatterns' => [],
'allowedHeaders' => ['*'],
'allowedMethods' => ['*'], // ex: ['GET', 'POST', 'PUT', 'DELETE']
'exposedHeaders' => [],
'maxAge' => 0,
];
Vue Component
methods: {
test(){
let config = {
headers: {
"X-AUTH-TOKEN": "uniqueApiToken",
"Access-Control-Allow-Headers": true
}
}
axios.get('https://v1.motorapi.dk/vehicles/ar24300', config)
.then(res => {
console.log(res.data);
})
.catch(err => console.log(err))
}
}
Console Message: