What the browser is telling you
- A page that was served from
https://admin.dev.mydomain.com is trying to make an XHR / fetch call to https://qa3-admin.staging.mydomain.com.
- Because the scheme + host + port are different, the browser treats this as a cross-origin request.
- Before the browser will send the actual request it looks for the CORS response headers coming back from
qa3-admin.staging.mydomain.com.
- The response it received does not contain the header
Access-Control-Allow-Origin: https://admin.dev.mydomain.com
(or Access-Control-Allow-Origin: *).
- Therefore the browser blocks the response and prints the message you see.
Where the headers must be added
The headers have to be emitted by the origin that is being called, i.e. the service behind qa3-admin.staging.mydomain.com.
In your architecture that request first hits the AWS ELB, then (usually) an Ingress controller inside the EKS cluster, and finally the application pod.
Any of those three layers can inject the headers, but the simplest and most explicit place is the application itself or the Ingress.
Typical fixes
A. Application-level (works everywhere)
If you control the code, add CORS middleware. Examples:
const cors = require('cors');
app.use(cors({
origin: 'https://admin.dev.mydomain.com',
credentials: true // if you send cookies
}));
@CrossOrigin(origins = "https://admin.dev.mydomain.com")
B. Ingress-level (if you use AWS Load Balancer Controller + NGINX/ALB)
NGINX Ingress example:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: qa3-admin
annotations:
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "https://admin.dev.mydomain.com"
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
ALB Ingress example:
alb.ingress.kubernetes.io/cors-allow-origin: 'https://admin.dev.mydomain.com'
alb.ingress.kubernetes.io/cors-allow-methods: 'GET,POST,PUT,DELETE,OPTIONS'
C. AWS API Gateway / CloudFront (if you have another layer)
Add the same Access-Control-Allow-Origin header in the gateway response or use the built-in CORS configuration.
Quick sanity check
curl -i https://qa3-admin.staging.mydomain.com/
You should now see
Access-Control-Allow-Origin: https://admin.dev.mydomain.com
- Hard-reload the browser tab; the error should disappear.
If you need to allow multiple origins, return the exact origin that the Origin request header contains instead of a wildcard (*) when credentials are involved.