- What is the local and remote URL that you are crossing over?
- It is impossible for a PHP
file_get_contents()of the local file system to cause a CORS error, HTTP is not involved here - Could the
app/public/address/countries+states+cities.jsonfile be somehow conflicting withhttp://website:6969/api/customer/address/countries?
Sep 19, 2020
15
Level 1
Reading json file from storage in controller triggers CORS problem
I've been having a CORS error in one page of my app, and after some troubleshooting i realized it's because of this (when i remove this part there's no more cors error)
$path = storage_path('app/public/address/countries+states+cities.json');
$content = collect(json_decode(file_get_contents($path), true));
here is the cors error i get:
Access to XMLHttpRequest at 'http://website:6969/api/customer/address/countries' from origin 'http:/website' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
this is especially weird because when i do add an Access-Control-Allow-Origin header i get the following error:
Access to XMLHttpRequest at 'http://website:6969/api/customer/address/countries' from origin 'http://website' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'http://website, *', but only one is allowed.
Also, this only works when i add the headers in nginx, otherwise i've tried adding cors middleware and headers in laravel but none of that seems to change anything, here's what i added in my nginx config (removed now):
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
Please or to participate in this conversation.