• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Angular Proxy Issue

 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm playing around with Angular, trying to create a weather forecast app.  I'm using the National Weather Service API for data.  There are 3 steps to retrieving a forecast:
1. get your latitude and longitude (the NWS doesn't offer geocoding, so we have to use a different api for this)
2. request the metadata ("points") for this location
3. using the points, request the forecast document.

Since this data resides on a server other than the one I'm working on, I need to proxy requests to the data servers.  I set up the proxy.conf.json like so:


Now, in my angular code, I make a request to the US Census Geocoder API:


The proxy rewrites this request and I get the latitude and longitude back.  The output from the proxy looks like:


Next, in my angular code, I perform the second step, taking the latitude and longitude and requesting the points from the NWS.  The URL I use looks like:


The output from the proxy is similar to the previous example, so it appears to do the correct thing rewriting the request:


However, I get a 404 error.  The weird thing is, the URL reported for the error isn't the one I requested nor is it the rewritten one.  

It's as if the proxy is trying to request the rewritten URL from localhost.

For another data point, I have another app in which I was working with another NWS API which basically goes by county (the API calls "zones").  Occasionally I will get failures when the service is overwhelmed.  The URL in those errors will be what I expect, the unrewritten URL with localhost:


Now, the API that uses zones doesn't require geocoding, so the app proxy config only has one entry for the https://api.weather.gov target.  This leads me to believe that I have configured the proxy incorrectly.  Is this the case or is there something else wrong?
Thanks



 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So apparently I'm sending too big a number.  The API doc says:

Please note that, for efficiency purposes, the API doesn’t support more than four decimal places of precision in coordinates. If you send a more precise coordinate, you’ll receive an error giving you the closest proper coordinate.


You can see above that the error I get is truncated to 4 decimal places.  The fact that the URL in the error message looks like the error was originating from localhost distracted me from this.  
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I ran into the same issue sending coordinates that end with a 0.  It looks like, rather than sending an HTML error response, the API sends a 301 response when it gets coordinates it doesn't like and my code doesn't handle that...
 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic