Cross origin error with Docker containers

Viewed 1792

I'm building an application with Microservices locally and then on docker containers I currently have Eureka, Zuul with Spring Security, a Microservice using Spring boot 2, and an Angular 6 client

I parametrized Spring Security on Zuul in order to manage security and CORS, extending WebSecurityConfigurerAdapter class, overriding configure method, ... Locally It works perfectly. My client (http://localhost:4200) has access to APIs through Zuul (http://localhost:8762/microservice/api/...), adding basic auth header with OPTION.

But with Docker containers, built with Docker Compose, it's not the same. Chrome throws an "Unknown Exception" while Firefox indicates a cross origin error during the OPTION request. APIs are called by the client through Zuul like that : http://gdt-gateway-proxy-service:8762/microservice/api/...

This is part of my docker-compose.yml file, concerning client (gdt-client) and Zuul (gdt-gateway-proxy-service) :

version: '2'
services:

    ...

    gdt-gateway-proxy-service:
        container_name: alpine-jdk8-gdt-gateway-proxy-service
        build:
            context: .
            dockerfile: Dockerfile.gdt-gateway-proxy-service
        image: alpine-jdk8-gdt-gateway-proxy-service:latest

        ...

        expose:
            - 8762
        ports:
            - 8762:8762
        networks:
            - gdt-network


    ...


    gdt-client:
        container_name: alpine-httpd-gdt-client
        build:
            context: .
            dockerfile: Dockerfile.alpine.httpd-gdt-client
        image: alpine-httpd-gdt-client:base
        expose:
            - 4200
        ports:
            - 4200:80
        networks:
            - gdt-network
        links:
            - gdt-gateway-proxy-service:gdt-gateway-proxy-service
        depends_on:
            - gdt-gateway-proxy-service
        logging:
            driver: json-file
networks:
    gdt-network:
        driver: bridge
1 Answers

I solved my issue adding the annotation @CrossOrigin above my controllers. It was not required locally.

Related