Reputation: 783
I have deployed Angular 7 app to Azure Storage Static Website.
Angular app makes calls to .NET Core API which is deployed to Azure App Service.
Is it possible to configure URL rewrite (reverse proxy) to route Angular app requests to .NET Core API without having to enable CORS? Similar way like using Angular proxy configuration for local development?
I have read that it is possible to use URL rewrite rules in Azure CDN, but I am not quite sure how to do it. https://learn.microsoft.com/en-us/azure/cdn/cdn-rules-engine-reference-features#url-rewrite
As far as I understand it is possible to specify only relative path in URL rewrite rule.
Any help is appreciated.
Upvotes: 10
Views: 7553
Reputation: 10979
You can use azure function proxy where your site is deployed. I am assuming for frontend you will have every url starting with /api.
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"root": {
"matchCondition": {
"route": "/api/{*route}",
"methods": [
"GET",
"HEAD"
]
},
"backendUri": "https://my-dot-net-server/{*route}": {
//If you want to override any headers
}
}
}
}
The above proxy will redirect your request to dotnet url and send the response.
Upvotes: 3
Reputation: 2054
So yes you can do this, but to have it enabled you need to use the Azure Premium CDN, which is actually not very expensive and is charged by usage, so if your site is not very busy it should be fine.
You will need to go into the CDN portal and rules engine and create a Url-rewrite.
It will look like this..
Notice the regex [^?.]*(\?.*)?$
this will basically match any route without a file path (no file extension). This then redirects to index.html
Hope that helps you.
Upvotes: 12