'Access-Control-Allow-Headers doesn't work in laravel 7
I have an application where in a view I need to use the following code
<script>
var config = {
method: 'get',
url: 'https://www.example.com',
headers: {
'X-Secret-Key': 'secret'
}
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
</script>
As you can see, it's because of axios, in the console I get "Access to XMLHttpRequest at "https://www.example.com' from origin 'http://localhost' has been blocked by CORS policy: Request header field x-secret- key is not allowed by Access-Control-Allow-Headers in preflight response.", my config/cors.php has the following configuration
<?php
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/*'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
What do I have to do so that this message does not continue to appear on the console and the information loads correctly?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
