0
votes

I am trying to follow the link below for forwarding my api request to another base url, in Azure API management service, which i had created by importing apis from one azure function app.

https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-deploy-multi-region

my policies look like

<policies>
    <inbound>
        <base />
        <choose>
            <when condition="@(context.Request.OriginalUrl.Host.Contains("centralus-01.regional"))">
                <set-backend-service base-url="https://apiservtmt.trafficmanager.net/api/" />
            </when>
            <when condition="@(context.Request.OriginalUrl.Host.Contains("southeastasia-01.regional"))">
                <set-backend-service base-url="https://apiservt.trafficmanager.net/api/" />
            </when>
            <otherwise>
                <set-backend-service base-url="https://apiservtmt.trafficmanager.net/api/" />
            </otherwise>
        </choose>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

but unfortunately even though i set the inbound policy to change the base url, post inbound policy is applied, the url is again getting reset to the original azure function that I had used to associate the apis with the api management. u can see in the trace log, even after setting it to the base url of my desired choice its getting reset. I tried every possible policy compbination, but still issue persists, please help.

api-inspector (0.322 ms)
{
    "request": {
        "method": "GET",
        "url": "https://apiservapimt.azure-api.net/xtxs/sds/",
        "headers": [
            {
                "name": "Sec-Fetch-Mode",
                "value": "cors"
            },
            {
                "name": "Ocp-Apim-Subscription-Key",
                "value": "*****************"
            },
            {
                "name": "Sec-Fetch-Site",
                "value": "cross-site"
            },
            {
                "name": "X-Forwarded-For",
                "value": "188888888888888"
            },
            {
                "name": "Cache-Control",
                "value": "no-cache, no-store"
            },
            {
                "name": "Content-Type",
                "value": "text/plain;charset=UTF-8"
            },
            {
                "name": "Accept",
                "value": "*/*"
            },
            {
                "name": "Accept-Encoding",
                "value": "gzip,deflate,br"
            },
            {
                "name": "Accept-Language",
                "value": "en-US,en;q=0.9,de;q=0.8,af;q=0.7"
            },
            {
                "name": "Host",
                "value": "apiservapimt.azure-api.net"
            },
            {
                "name": "Referer",
                "value": "https://apimanagement.hosting.portal.azure.net/apimanagement/Content/1.0.574.0/apimap//apimap-apis/index.html"
            }
        ]
    }
}
api-inspector (0.003 ms)
{
    "configuration": {
        "api": {
            "from": "/",
            "to": null,
            "version": null,
            "revision": "1"
        },
        "operation": {
            "method": "GET",
            "uriTemplate": "/jsdhakj/{surveyId}/"
        },
        "user": "-",
        "product": "-"
    }
}
cors (0.474 ms)
"Origin header was missing or empty and the request was classified as not cross-domain. CORS policy was not applied."
choose (0.010 ms)
{
    "message": "Expression was successfully evaluated.",
    "expression": "context.Request.OriginalUrl.Host.Contains(\"centralus-01.regional\")",
    "value": false
}
choose (0.003 ms)
{
    "message": "Expression was successfully evaluated.",
    "expression": "context.Request.OriginalUrl.Host.Contains(\"southeastasia-01.regional\")",
    "value": false
}
set-backend-service (0.005 ms)
{
    "message": "Backend service URL was changed.",
    "oldBackendServiceUrl": "",
    "newBackendServiceUrl": "https://apiservtmt.trafficmanager.net/api/",
    "request": {
        "url": "https://apiservtmt.trafficmanager.net/api/adhsakjd/sds/"
    }
}
**set-backend-service (0.005 ms)
"Backend 'apiservt' set to current."**
**Backend
(668.101 ms)↑ Back to top
set-backend-service (0.030 ms)
{
    "message": "Backend service URL was changed.",
    "oldBackendServiceUrl": "https://apiservtmt.trafficmanager.net/api/",
    "newBackendServiceUrl": "https://apiservt.azurewebsites.net/api",
    "request": {
        "url": "https://apiservt.azurewebsites.net/api/surveys/sds/"
    }
}**
set-header (0.019 ms)
{
    "message": "Specified value was assigned to the header (see below).",
    "header": {
        "name": "x-functions-key",
        "value": "hjwjrhewj"
    }
}
forward-request (0.101 ms)
{
    **"message": "Request is being forwarded to the backend service. Timeout set to 300 seconds",
    "request": {
        "method": "GET",
        "url": "https://apiservt.azurewebsites.net/api/surveys/sds/",
        "headers": [**
            {
                "name": "Host",
                "value": "apiservt.azurewebsites.net"
            },
            {
                "name": "Request-Id",
                "value": "|9ab257c67368465b904f288b38b44118.c248de116fca4824_83e3e6e7."
            },
            {
                "name": "Sec-Fetch-Mode",
                "value": "cors"
            },
            {
                "name": "Ocp-Apim-Subscription-Key",
                "value": "wrewrwer"
            },
            {
                "name": "Sec-Fetch-Site",
                "value": "cross-site"
            },
            {
                "name": "X-Forwarded-For",
                "value": "shakjdhkjsa"
            },
            {
                "name": "Cache-Control",
                "value": "no-cache, no-store"
            },
            {
                "name": "Content-Type",
                "value": "text/plain;charset=UTF-8"
            },
            {
                "name": "Accept",
                "value": "*/*"
            },
            {
                "name": "Accept-Encoding",
                "value": "gzip,deflate,br"
            },
            {
                "name": "Accept-Language",
                "value": "en-US,en;q=0.9,de;q=0.8,af;q=0.7"
            },
            {
                "name": "Referer",
                "value": "https://apimanagement.hosting.portal.azure.net/apimanagement/Content/1.0.574.0/apimap//apimap-apis/index.html"
            },
            {
                "name": "Request-Context",
                "value": "appId=cid-v1:552f0e64-cebd-4730-b0b8-8cf0a0fa6caf"
            },
            {
                "name": "x-functions-key",
                "value": "shdsajdhskjf"
            }
        ]
    }
}
forward-request (667.950 ms)
{
    "response": {
        "status": {
            "code": 401,
            "reason": "Unauthorized"
        },
        "headers": [
            {
                "name": "Transfer-Encoding",
                "value": "chunked"
            },
            {
                "name": "Request-Context",
                "value": "appId=cid-v1:552f0e64-cebd-4730-b0b8-8cf0a0fa6caf"
            },
            {
                "name": "Content-Type",
                "value": "application/json; charset=utf-8"
            },
            {
                "name": "Date",
                "value": "Tue, 24 Sep 2019 17:40:07 GMT"
            }
        ]
    }
}
Outbound
(0.146 ms)↑ Back to top
transfer-response (0.050 ms)
{
    "message": "Response headers have been sent to the caller."
}
transfer-response (0.096 ms)
{
    "message": "Response body streaming to the caller is complete."
}
1

1 Answers

1
votes

its resolved now. there was another set base url policy getting added at each operation level while importing the apis from the azure function. by removing these, picked the parent policy.