Reputation: 3631
I have an VM running an Express App on port 3001; I am using Azure APIM in front of the VM; The APIM simply forwards all requests to port 3001 on the VM.
The frontend React app sends GET request to the APIM and get response with status code 200.
However, the log of the Express App running in the VM shows that it never received any requests from the APIM;
This is the Effective policy of the API:
<policies>
<inbound>
<!--base: Begin Global scope-->
<cors allow-credentials="true">
<allowed-origins>
<origin>https://john.z11.web.core.windows.net/</origin>
<origin>https://api-management-john-dev.developer.azure-api.net</origin>
<origin>http://localhost</origin>
</allowed-origins>
<allowed-methods preflight-result-max-age="120">
<method>GET</method>
<method>POST</method>
<method>PUT</method>
<method>DELETE</method>
<method>OPTIONS</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
<expose-headers>
<header>*</header>
</expose-headers>
</cors>
<rate-limit-by-key calls="300" renewal-period="120" counter-key="@(context.Request.IpAddress)" />
<!--base: End Global scope-->
</inbound>
<backend />
<outbound />
<on-error />
</policies>
The NSG of the APIM subnet has outbound rules that allow ANY traffic to go anywhere.
The NSG of the VM subnet has inbound rules that allows traffic from the subnet of the APIM to visit port 3001:
The VM has ip address 10.0.0.4
In the APIM, in the API settings, the Web service URL is set to https://10.0.0.4:3001
In the browser dev console, the GET request is getting response code "200, OK":
However, the request never got to the VM on port 3001.
What is missing?
I have set up Diagnostic settings in APIM and I checked the Log Analytics workspace, here is a log message:
TenantId 7a3f7378-f840-46f9-123qwe123qwe
TimeGenerated [UTC] 2023-07-04T11:56:15.3059347Z
OperationName Microsoft.ApiManagement/GatewayLogs
CorrelationId 0ef5dda1-7655-123qwe123qwe123qwe
Region Japan East
IsRequestSuccess true
Category GatewayLogs
TotalTime 0
CallerIpAddress 123.65.123.123
Method GET
Url https://api-management-john-dev.azure-api.net/api/user
ClientProtocol HTTP/1.1
ResponseCode 200
ResponseSize 231
Cache none
...
It does not say anything about passing the request to backend though
Upvotes: 0
Views: 235
Reputation: 3631
Found the reason:
I am missing a <forward-request />
tag in my policies; As simple as that.
Check Doc here: https://learn.microsoft.com/en-us/azure/api-management/forward-request-policy#forward-request-with-timeout-interval
Upvotes: 0