I have a Blazor WASM app deployed to an Azure Static Web app. I've managed to find out how to handle SPA routing, but I can't figure out how to rewrite requests to my API (hosted on an Azure Web app, but under a different url). My staticwebapp.config.json looks like this:
{
"routes": [
{
"route": "/api/*",
"rewrite": "https://backend.com/*"
}
],
"navigationFallback": {
"rewrite": "index.html",
"exclude": [ "/images/*.{png,jpg,gif}", "/css/*" ]
}
}
But when I do that, I'm getting a 405 error (presumably because it's trying to do https://frontend.url/api/somerequest
, then endpoint is definitely taking POST requests), if I add another API in and try that, it then just return my index.html file.
Is it impossible to reroute to another URL? And if yes, what do I need to do differently?
Source code is available on GitHub here.
Going to leave an answer here if someone has the same idea and stumbles across this.
You cannot redirect to external url using the staticwebapp.config.json. External URL is everything beyond your root url, even if it's a service hosted on Azure (say a web app). It used to be possible with earlier versions of Azure Static Web app, see this question for example: Rewrite URL for static website hosted in Azure Storage
There are two answers to this: