Netlify proxy redirect - referencing dynamic variable

Hey all. Just successfully deployed my app but struggling to fix one nagging issue. Is it possible to dynamically update a variable inside a redirect? The redirect URL will stay the same, it’s just the “searchTerm” variable that’ll be set when you search for something. If I hardcode searchTerm to milk for example then it works. I need to redirect it as I’m getting blocked by cors. Locally I’ve been using cors-anywhere to get around this issue. The other 2 stores are already working if someone visits the app, it’s just ‘Countdown aka Woolworths’ that I’m trying to sort.

// netlify.toml

  [[redirects]]
  from = "VITE_PROXY"
  to = "https://www.woolworths.co.nz/api/v1/products?target=search&inStockProductsOnly=true&search=${searchTerm}"
  status = 200
  force = true

I had a look at https://docs.netlify.com/configure-builds/file-based-configuration/#inject-environment-variable-values but unfortunately that only mentioned environment variables & not dynamic ones. Also had a go at searching the forums. Lastly I tried referencing “VITE_PROXY” + my variable when fetching, but that just concatenates it & nullifies the redirects rule. Hoping someone could help, thanks!

@Spykerwolf You’re just looking at the wrong portion of the documentation.

What you’re looking for is the redirect/rewrite/proxy documentation.
https://docs.netlify.com/routing/redirects/redirect-options/

Specifically these sections:
Splatshttps://docs.netlify.com/routing/redirects/redirect-options/#splats
Placeholdershttps://docs.netlify.com/routing/redirects/redirect-options/#placeholders
Query Parametershttps://docs.netlify.com/routing/redirects/redirect-options/#query-parameters

As it says at the top of the page:

Most of the examples on this page use the _redirects file syntax, but all of these options are available in the Netlify configuration file syntax as well.

1 Like

You just made my day thank you Nathan. Not sure how I missed that, but it’s working now woohoo!

glad to hear you found a solution @Spykerwolf