3

I need to store cookies for my http requests in my app so I set $httpProvider.defaults.withCredentials = true;

However, upon setting this I got an error when doing http requeust:

A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:8100' is therefore not allowed access.

I believe this error will not show on devices but I want to debug the app using my pc's web browser. I tried to configure my config.xml and setting access origin to localhost:8100 but it doesn't work either.

I'm also using Chrome's Allow-Control-Allow-Origin: * but no luck too.

dgzz
  • 2,837
  • 6
  • 30
  • 53

1 Answers1

3

Correct, when running your ionic app on a mobile device as an app, or in the emulator the CORS restrictions do not apply.

You can disable these restrictions in Google Chrome with the --disable-web-security flag. See https://stackoverflow.com/a/6083677

This flag does reduce your browsers security so I would only keep it disabled while developing your application and relaunch chrome without the flag before doing any other web browsing.

Community
  • 1
  • 1
oznu
  • 1,409
  • 2
  • 11
  • 11
  • Try launching chrome with web security disabled? See http://stackoverflow.com/a/6083677 for details on how to do it. – oznu Aug 09 '15 at 13:10
  • 1
    Did you completely close Chrome before trying to launch it with the flag? You should have also gotten a yellow warning bar in chrome on launch - which you can dismiss - letting you know web security is disabled. – oznu Aug 09 '15 at 13:42
  • It works now, it needed ALL chrome instances to be closed before applying the flag. Thanks! – dgzz Aug 09 '15 at 13:51