ozee31 / cakephp-cors

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

Cors\Error\AppExceptionRenderer override crud's JSON API one #5

Closed eymen-elkum closed 7 years ago

eymen-elkum commented 7 years ago

In the case that crud' json api listener is using, the error cors Exception Rendered overrides Crud\Error\JsonApiExceptionRenderer

how can we fix this?

ozee31 commented 7 years ago

I will add the possibility of not modifying exceptionRenderer.

But if you don't use exceptionRenderer see https://github.com/ozee31/cakephp-cors#errorcontroller to activate CORS if you have an exception

eymen-elkum commented 7 years ago

thanks @ozee31 i will follow that

bravo-kernel commented 7 years ago

Any chance we can get an example of how to disable the CORS exception renderer when using JsonApiListener (so I can update the blog so people won't have broken validation when following the tutorial.

ozee31 commented 7 years ago

It's released:

just change cors config in your app.php like

'Cors' => [
    'exceptionRenderer' => false
]
bravo-kernel commented 7 years ago

Thanks, didn't get that. I will update the blog accordingly. Good job 👍

bravo-kernel commented 7 years ago

Not working for me, I am not getting no JSON API errors and no validation errors. Anything I could be missing here?

bravo-kernel commented 7 years ago

Seems false doesn't quite do it for Crud's JsonApiListener. This however, does work:

    'Cors' => [
        'exceptionRenderer' => '\Crud\Error\JsonApiExceptionRenderer'
    ],
eymen-elkum commented 7 years ago

Hi @bravo-kernel I fixed it by using the deprecated header function in the error controller my PR for this may caused this problem

    public function beforeRender(Event $event)
    {
        parent::beforeRender($event);

        //$this->response->withHeader('Access-Control-Allow-Origin:', '*');
        $this->response->header(['Access-Control-Allow-Origin' => '*']);
        $this->viewBuilder()->setTemplatePath('Error');
    }
lpj145 commented 7 years ago

hey guys, i have same error, how did you solved ?