G
G
guerragro2019-07-25 05:43:57
Angular
guerragro, 2019-07-25 05:43:57

Problem with Access-Control-Expose-Headers?

getDataCounty() {
const headers = {
'Access-Control-Allow-Origin' : ' 127.0.0.1:4200 ',
};
const params = {
token: 'my-token'
};
return this.http.get(' api.travelpayouts.com/data/en ' +
'cities.json', {headers: (headers), params: (params)});
}
}
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.
I understand the reason, but I can't understand why I can't find a way out

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2019-07-25
@search

`Access-Control-Allow-Origin` is the header of the response from the server, not the header of the request. It must be exposed on the server. If you don’t know which domain the request will come from, then you need to set `Access-Control-Allow-Origin: *`
This problem cannot be solved on the client, but angular provides a proxy for development time (here I wanted to insert a link to the documentation, but stupid toaster prohibits the use of links). This proxy will not work on prod/staging. So the problem will still have to be solved by installing the necessary headers on the server.
If anything, the phrase "No 'Access-Control-Allow-Origin' header is present on the requested resource." translated into Russian as "Heder 'Access-Control-Allow-Origin' is not present on the requested resource"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question