leafsphp / cors

🔖 CORS module for leaf + PHP
https://leafphp.dev/modules/cors/
2 stars 0 forks source link

No 'Access-Control-Allow-Origin' #3

Open webds opened 1 year ago

webds commented 1 year ago

https://github.com/leafsphp/cors/blob/10934a7504879ecf9b6f7687926c22a3b5c02ce9/src/Cors.php#LL71C4-L71C4

There is an error here. If we want to set a custom Allow-Origin, we won't be able to do it. For example, if I want to set the value "*", it will still not be accepted. The AJAX request will throw an error: ...has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

webds commented 1 year ago

my quick solution

             if (static::isOriginAllowed($origin)) {
            $originHeader = ($origin == '*')?$origin:($_SERVER['HTTP_ORIGIN'] ?? $_SERVER['HTTP_HOST']);
            Headers::accessControl(
                'Allow-Origin',
                 $originHeader
            );
        }
mychidarko commented 1 year ago

Hi @webds, I'm just seeing this issue. Do you mean you are not able to set your own origins using app()->cors()

bbauti commented 1 year ago

hey! im having the same error, i dont know what to do to solve it