Forum Discussion
What's the secret sauce for getting Functions API to work with static web site?
Kidd's managed-functions route is one way in, but there's a second option that's probably the one you want, because your function is already its own project running on localhost:7071 — you don't have to move it into the static site's repo at all.
Your config is fine, by the way. The route rule and the navigationFallback exclusion are both right, so stop fiddling with the JSON — the problem is that nothing is attached behind /api on the deployed site, so the request has nowhere to go. Locally it works because the Functions host is running; on Azure, /api only means something once an API backend is attached to the static web app.
There are two ways to attach one. The first is the managed route Kidd described: an api folder at the root of the repo that gets built and deployed with the site. The second is to link the function app you already have: in the portal, open the static web app, go to Settings and then APIs, and on the Production row choose Link, pick Function App and your function app. From then on, /api/image/123 on your static site's address proxies straight through to the same function — the function app's endpoint needs to keep its /api prefix, since that's what the static app matches on.
Two catches before you do it. Linking needs the Standard plan on the static web app, so if you're on the free tier that's the first thing to check. And if your workflow file has an api_location set, clear it to an empty string first, because a linked backend and a managed api folder can't both be in play at once. If you only need this one site, the managed route is simpler; if the function is meant to serve other things too, linking is the right call.