I have design adapter in ember js which send requests to backend to get the data but getting a error
"XMLHttpRequest cannot load https://example.com/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access."
in console.
I can solve the problem if I use the following code in nginx config file on my server.The backend is designed using django.
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
But I don't want to disturb the tha nginx config.
adapter
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host:"https://example.com/api/",
});
How to send the request so that it doesn't show any error
Unfortunately, you're going to have to edit your server's config file. Otherwise, you would have to serve the app from the same domain and port as your back-end.