I have a .NET Core API hosted on Azure (azure app service) and it is running behind APIM. I now need to call this API from a front-end (again using the APIM endpoint) and I have been unable to set up CORS properly. I do not want to define CORS in code - my .NET code has zero CORS policy setup.
CORS is set up at the app service level by adding the allowed origins in the CORS blade but the preflight request still comes without CORS header when calling the API through APIM (thus I get "Response to preflight request doesn't pass access control check..."). I have added a CORS policy to the APIM instance for All Operations for the respective API but it still does not work. The "Options" request comes back without the Access-Control-Allow-Origin header on the browser debugger. If I skip APIM and call the API directly, it works fine. Am I missing something obvious here?
<policies>
<inbound>
<base />
<cors>
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
<method>OPTIONS</method>
<method>TRACE</method>
<method>PUT</method>
<method>DELETE</method>
<method>HEAD</method>
<method>PATCH</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
</cors>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>*</value>
</set-header>
</outbound>
<on-error>
<base />
</on-error>
</policies>
Note that I also tried to specifically add the front-end URL https://frontend.com in those settings and check Allow Credentials checkbox, which also changed nothing.
When I added the set-header option, if I directly call the API via postman then the Access-Control-Allow-Origin is returned on the postman call, but on the browser preflight request still nothing.
EDIT:
Per response.. I tried to simplify the scenario by creating a brand new API with the template "weather forecast" .net core api deployed to it. No authentication and CORS policy set to *. I proceeded to add this API to my APIM instance - simply clicked the App Service option in the APIM menu and added CORS policy - nothing else. Then, in a separate URL (for CORS to trigger) I deployed a simple HTML with a call to the new APIM endpoint. The headers look exactly the same - no CORS header and the call fails, if I skip APIM and call backend directly it works. I cannot spot any error in my set up at this point, no idea what I may be missing. Screenshots below