'Can I redirect with wildcard in Azure Static Web App?
I'm trying to redirect API calls from my Static Web App to another Function App but I can't get wildcard to work.
The route matches correctly but I want the *
part to be included in the redirect.
This is an example from my staticwebapp.config.json
{
"route": "/api/client/*",
"redirect": "https://xx.yy.net/api/client/*"
}
I would like the request /api/client/customer/get?customerId=xx
to become https://xx.yy.net/api/client/customer/get?customerId=xx
.
But whatever I try it only hard routes to exactly what I put in the redirect. With functions this is possible with a proxy but I can't find a way in a Static Web App.
Solution 1:[1]
A bit late, but in my case it was possible to get the original Url from a header:
if (shortUrl == "*")
{
var original = req.Headers
.FirstOrDefault(h => h.Key.ToLower() == "x-ms-original-url")
.Value.FirstOrDefault()?.ToString();
if (string.IsNullOrWhiteSpace(original))
{
shortUrl = "";
}
else
{
shortUrl = original.Split("/")
.Where(p => !string.IsNullOrWhiteSpace(p))?
.LastOrDefault() ??"";
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mcafee |