Load balancer CORS Preflight Rejected


OK here goes,

I have 2 servers, identical config, HTTP API, port 80 and Cloudflare cert on 443.

Server 1 DNS, A record, api-server-1.domain.com → IP
Server 2 DNS, A record, api-server-2.domain.com → IP

Load balancer on api.domain.com

One pool with the 2 servers above.

When I make a request to api.domain.com , there is a HTTP redirect to one of the servers. This bit works.

But, I have a website on www.domain.com, which consumes the API. Problem is when the web app makes a CORS preflight request, the OPTIONS response contains a redirect, which is not allowed,

preflight is invalid (redirect) or redirect is not allowed for a preflight request

How do I fix this?

Originally I thought the load balancer would always present itself as api.domain.com and hide the underlying servers but that is not the case. What am I missing?



Also, for every request now going through the load balancer, there will be twice as many requests, eg,

GET api.domain.com → redirect to origin server, eg api-server-1.domain.com
GET api-server-1.domain.com → response .

This doesn’t seem right :confused:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.