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:
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?
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.
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...