I’m having trouble with a proxy redirect in my netlify.toml file.
[[redirects]]
from = "/api/current-conditions/"
to = "https://api.openweathermap.org/data/2.5/weather?units=imperial&APPID=OPENWEATHER_API_KEY_REPLACE"
query = {q = ":q"}
status = 200
force = true
headers = {X-From = "Netlify"}
The API Key is being injected to the redirect rule on build (as described here: https://docs.netlify.com/configure-builds/file-based-configuration/#inject-environment-variable-values), which is working perfectly on my local machine using Netlify Dev (console shows “Proxying to…” on API calls, data is returned without errors). Despite no build errors, when I deploy my branch to Netlify the API I am calling returns an error.
{
"cod": "400",
"message": "Nothing to geocode"
}
Confirmed working destination API call (key removed for this post): https://api.openweathermap.org/data/2.5/weather?units=imperial&q=Denver&APPID=REMOVED_API_KEY_FOR_FORUM_POST
The non-working API call using the Netlify redirect, on a branch deploy: https://5f2e2b3b91db3b000752d71d--ocp-weather-dash.netlify.app/api/current-conditions?q=Reno
I’m able to reproduce the “Nothing to geocode” error on the destination API call if I drop the “&q=Denver” query (https://api.openweathermap.org/data/2.5/weather?units=imperial&APPID=REMOVED_API_KEY_FOR_FORUM_POST), so I’m thinking that its something with query = {q = ":q"}
in my redirect rule.
I’m not sure why this would work locally with Netlify Dev but not on Netlify.app after deploying- any help here is greatly appreciated!
For troubleshooting, I’m also curious if its possible to see redirect logs on a deployment, similar to what Netlify Dev shows in the console on my local machine any time it executes a redirect.