Search code examples
springspring-mvcspring-bootnetflix-zuul

How to disable CORS within a Zuul / Spring Boot microservice setup? (route CORS OPTIONS preflights)


In our setup Zuul should act as router for our Microservices. This means that also CORS OPTIONS request should be routed to our Microservices (noone else knows about the correct CORS settings...).

How to setup Spring-Boot/Spring-MVC/Zuul that it routes the CORS to the microservices?

There are many Answers around how to enable and how to configure cors. But they aim on how to enable CORS or "allow every domain". There is no answer how to disable the CORS handling on a Spring-Boot with Zuul setup.


Solution

  • The Problem is that Spring-Boot in its autoconfiguration hijacks the CORS OPTIONS requests and isn't forwarding it to the zuul part. To disable the CORS Filter just put this into your application properties or yml.

    spring.mvc.dispatch-options-request=true
    

    Now the CORS Requests are forwarded to your microservices.