Hello Team.
I hope you are doing well.
I have Traefik with EntryPoint 80 and 443. and behind 3 services. I am using also docker-compose.
FE and API have nginx inside of the container.
In front we have react and in API is configured to let all headers, also nginx is configured to handle CORS too. I don't have any idea how to resolve this. Also this is my second project with Traefik, first with multiple services which needs to talk. Please see attached screenshot
======something.com========
something.com ===traefik==
=====api.something.com=======
If I try postman I can get token from API, but in firefox I get error.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.something.com/api/account/login. (Reason: CORS header ‘Access-Control-Allow-Origin’ does not match ‘https://something.com, *’).
nginx config
if ($request_method = 'OPTIONS') {
return 204;
}
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' '*' always;
add_header 'Access-Control-Allow-Headers' '*' always;
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
Backend-traefik :
backend:
container_name: something-backend
image: git something.com:5050/ something-backend-backend:production
restart: unless-stopped
networks:
- something-network
labels:
- "traefik.enable=true"
- "traefik.http.routers.backend.rule=Host(`api. something.com`)"
- "traefik.http.routers.backend.service=backend"
- "traefik.http.services.backend.loadbalancer.server.port=80"
- "traefik.http.routers.backend.entrypoints=web"
- "traefik.http.middlewares.backend.headers.accesscontrolalloworiginlist=*"
- "traefik.http.routers.service.middlewares=viewsheaders"
- "traefik.http.middlewares.backend.headers.accesscontrolallowmethods=GET,OPTIONS,PUT"
- "traefik.http.middlewares.backend.headers.accessControlExposeHeaders=*"
Thank you in advance.