apigee preflight OPTIONS request passes with 200 with CORS, but later GET request fails with error.

Apigee preflight OPTIONS request passes with CORS headers in the response. But, the real request to GET the resource fails with the error message as below.The GET request does not fail all the time. It fails around once in a while.

Access to fetch at '***' from origin '***' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.


Below is the CORS policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="add-cors">
    <DisplayName>Add CORS</DisplayName>
    <FaultRules/>
    <Properties/>
    <Add>
        <Headers>
            <Header name="Access-Control-Allow-Origin">{allowed_origins}</Header>
            <Header name="Access-Control-Allow-Headers">origin, x-requested-with, accept, content-type, apikey</Header>
            <Header name="Access-Control-Max-Age">3628800</Header>
            <Header name="Access-Control-Allow-Methods">GET</Header>
        </Headers>
    </Add>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

0 3 1,272
3 REPLIES 3

Pls provide your trace for both the options and the get requests. Additionally paste your flow where the CORS policy is included.

You may want to check the allow origins variable and any conditions specified for your cors policy execution

Can you trace for unsuccessful request and validate if the GET request is reaching Apigee or not. If not, then PREFLIGHT is unsuccessful.

If PREFLIGHT succeeds, I suspect header "Access-Control-Allow-Origin" is not getting added in response for some scenario (Maybe when Fault Rules are executed? - Just guessing)

Is it possible for you to attach the proxy zip and curl for which the request fails?

@Gagandeep Singh I agree with you if I am using different requests. But for a given request it passes once and fails another time. It is occurring intermittently. Will try to share the details u asked soon.