How to use npm package cors?

Make a request to Google using angular $http error
XMLHttpRequest cannot load http://maps.googleapis.com/maps/api/geocode/json?address=%D0%94%D0%BE%D1%81&sensor=false. Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.


Found this package cors, write that will help if you add code to your app.use('cors());

There is no effect.

What to do ? Why is not working?
July 9th 19 at 13:46
1 answer
July 9th 19 at 13:48
Solution
cors is Midler to express the library running on the server and angular (running on the client) has nothing to do with
If a third-party API does not give the CORS headers from the client side You can not inquire, but it is possible to proxy the request on the server
hmm, it does not matter? Because the request goes from my server to the Google server. No matter where you need to turn it on, no? - Burnice.Weber commented on July 9th 19 at 13:51
: CORS is used by browsers for security cross-domain requests, if the site requests with ajax a resource from a different domain, the browser first sends an OPTIONS request contains the headers, from what domain the request came, the server must allow queries by using the response headers.
the cors module connected to express just the same, and monitors the OPTIONS queries and answers them according to their settings - geovanni_Hegmann commented on July 9th 19 at 13:54
: How then can we solve the problem? - Burnice.Weber commented on July 9th 19 at 13:57
: send a request to your own server, from the server, send a request to the API, for example, using the module request for node.js - geovanni_Hegmann commented on July 9th 19 at 14:00
'Ah!' that's what proxying. understood. Thank you! - Burnice.Weber commented on July 9th 19 at 14:03

Find more questions by tags AngularNode.jsCORS