How to configure preflight requests in Ocelot gateway?

Viewed 92

I have an Ocelot gateway that routes and handles my API server request.The problem is that I use CORS Policy in APIs, when a request comes from the web browser to APIs and I need to get preflight request and route to the specific API. Now I can't fix the problem in Ocelot gateway. How could I fix it?

The following code is an API sample:

[EnableCors(origins: "*", headers: "*", methods: "*")]
[Route("api/Balance")]
public GeneralResult<DTOResponse> Post(DTORequest req)
{
    var result = new GeneralResult<DTOResponse>();
    try
    {
    .
    .
    .
    }
    catch (Exception ex)
    }
        return result;
    }
}
[Route("api/OPTIONS")]
[AcceptVerbs("OPTIONS")]
public HttpResponseMessage Options()
{
    var resp = new HttpResponseMessage(HttpStatusCode.OK);
    resp.Headers.Add("Access-Control-Allow-Origin", "*");
    resp.Headers.Add("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
    return resp;
}
0 Answers
Related