ozee31 / cakephp-cors

A CakePHP (3.3+) plugin for activate cors domain in your application
MIT License
43 stars 31 forks source link

Add CORS to exception #7

Closed lpj145 closed 6 years ago

lpj145 commented 7 years ago

How add CORS on any exceptions ? when i have code 422 or 409 CORS not enabled.

ozee31 commented 7 years ago

Thank you for your issue, I look at this ASAP

ozee31 commented 7 years ago

If you use default config, exception work with CORS.

But if you use an other ErrorController you can add this in you ErrorController:

public function beforeRender(Event $event) {
    // ...
    $this->response = $this->response->withHeader('Access-Control-Allow-Origin', '*');
}
ozee31 commented 7 years ago

Can you test the new release? https://github.com/ozee31/cakephp-cors/releases/tag/v1.1.0

andreyg-moby commented 7 years ago

FYI,

It led to a problem in withCredentials cases where wildcard is not valid. Please try to keep CorsMiddleware logic even in exceptions.

ozee31 commented 7 years ago

ok @andreyg-moby I would update Exceptions in the next release

andreyg-moby commented 7 years ago

@ozee31 as it hangs here for a while, I've added PR for my workaround: https://github.com/ozee31/cakephp-cors/pull/14

Please review, merge & release.