Home
Support Forums

Redirect to function on another Netlify site

Site A (frontend): competent-ardinghelli-0dde0e
Site B (data and function): stoic-galileo-1d5a50

I have the following redirect in the netlify.toml for Site A:

[[redirects]]
  from = "/api/search"
  to = "https://stoic-galileo-1d5a50.netlify.app/.netlify/functions/search"
  status = 200
  force = true

The function takes a single query parameter term, and I’m hoping to call https://competent-ardinghelli-0dde0e.netlify.app/api/search?term=searchterm.

While the redirect appears to work, the request fails in browser (Firefox provides an actual error, while others never return or return empty responses):

curl ing the request also produces an error:

curl: (18) transfer closed with 623 bytes remaining to read

The function itself works as expected both locally and when called directly via Site B.

Is there a way for me to proxy from a URL on Site A to a function call on Site B?

Hey @andrewbridge,
When I try to curl https://stoic-galileo-1d5a50.netlify.app/.netlify/functions/search directly, I get a 401. So can you confirm that it returns what you would expect? That way we can at least narrow the issue to being about proxying.

Hi @jen,

Sorry about that, I’ve since put in some basic CORS checks into the function.

If you run:

curl -H "Origin: competent-ardinghelli-0dde0e.netlify.app" https://stoic-galileo-1d5a50.netlify.app/.netlify/functions/search\?term\=jackson

You should receive:

{"posts":[{"route":"/reviews/michael-jackson-bad","title":"Bad // Michael Jackson"},{"route":"/reviews/bat-for-lashes-lost-girls","title":"Lost Girls // Bat for Lashes"},{"route":"/reviews/prince-purple-rain","title":"Purple Rain // Prince"},{"route":"/reviews/kate-bush-hounds-of-love","title":"Hounds of Love // Kate Bush"}],"tags":[{"title":"michael jackson","route":"/tags/michael jackson"}]}

(Actual results may vary, but the structure is accurate)

Let me know if there’s any further information I can provide.

Thanks,
Andrew

Dang, I’ve hit this bug before :frowning: It hasn’t been fixed yet but @luke proposed a solution to a similar problem over here --> Proxying from one app to another Want to give that a try and let us know if it fixes things for you?