The issue could be due to the order of your firebase.json rewrites. If
{
"source": "**",
"destination": "/index.html"
}
is at the top of your rewrites then everything will match the "**" wildcard first, which is not what we want.
Instead, put the api (or whatever) rewrites first and put "**" last. E.g:
"rewrites": [
{
"source": "/api/**",
"function": "api"
},
{
"source": "**",
"destination": "/index.html"
}
]
This way the "/api/**" route is caught first and then everything else falls through. (Obvious in hindsight...)
Hope this helps save someone else a few hours!