Welcome Guest, Not a member yet? Register   Sign In
ci3 cors doesn't works
#5

(This post was last modified: 12-03-2020, 03:45 AM by tgix.)

CORS is ... fun ... In my current project I have a Sencha Ext JS front-end and a CI 4.0.4 back-end and it's working fine.

Have you checked the debugger in the browser for any messages? 
In Chrome you have to select "All" under Network tab to see the OPTIONS requests (they don't show up under XHR for some reason). 
I also use Charles proxy to really see what's going on.

I route all my OPTIONS request to a single function that returns this:
PHP Code:
        return $this->response->setHeader('Access-Control-Allow-Methods''DELETE, POST, GET, PUT, OPTIONS')
            ->setHeader('Access-Control-Allow-Headers',
                'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With')
            ->setHeader('Access-Control-Max-Age''3600')
            ->setHeader('Access-Control-Allow-Origin''https://my.frontend.url/')
            ->setHeader('Access-Control-Allow-Credentials''true')
            ->setStatusCode(204); 

If the browser is happy with that it will send the actual request.


For my front-end the withCredentials needs to be set on the XHR request (https://developer.mozilla.org/en-US/docs...redentials) and also cors to generate XDomainRequests (https://docs.sencha.com/extjs/7.2.0/mode....Ajax.html)

Remember that cookies could also be hard to get working cross-domain. I'm using Bearer Authorization instead.

Good luck! /Mattias
Reply


Messages In This Thread
ci3 cors doesn't works - by ultegro778 - 11-29-2020, 11:47 AM
RE: ci3 cors doesn't works - by InsiteFX - 11-30-2020, 12:16 PM
RE: ci3 cors doesn't works - by ultegro778 - 12-02-2020, 12:35 PM
RE: ci3 cors doesn't works - by InsiteFX - 12-02-2020, 10:36 PM
RE: ci3 cors doesn't works - by tgix - 12-03-2020, 03:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB