Search code examples
ember.jsember-dataember-cli

Ember app has been blocked by CORS policy


I was trying to use my api and I have a function on ember app to login but when the login action is trigerred I receive a message below. What is the reason I am receiving this error?

login:1 Access to fetch at 'https://app-dev.some-url.com.au/api/login' from origin
'http://localhost:4099' has been blocked by CORS policy: Response to preflight request doesn't
pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested
resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch 
the resource with CORS disabled.

Solution

  • Your API server isn’t configured to accept requests that come from a web application on another origin. Some options:

    1. Configure your API to serve the Access-Control-Allow-Origin header on the OPTIONS request that the browser makes to test this. It could be Access-Control-Allow-Origin: * if you’re lazy or can’t know in advance what origins people will be coming from. It’s hard to be more specific about this without knowing details of your API.

    2. Use Ember CLI’s API proxying feature to bypass the need for CORS. This is for development mode only, though. You’d need a similar solution in production where Ember CLI’s development server isn’t present.