grailscorsgrails-3.0

How to enable CORS in Grails 3.0.1


I would like to do cross origin communication using Grails in server side. The only documentation that I found is this one

https://grails.org/plugin/cors

but this is for an old version of Grails. The other documentation that I found is for spring:

https://spring.io/guides/gs/rest-service-cors/

so I added the file SimpleCorsFilter.groovy to init/myproject/ folder, but I don't know how to wire this component into resources.groovy


Solution

  • So, if you got here using grails 3.2.+ you can use the default way.

    Go to your application.yml and add:

    grails:
        cors:
            enabled: true
    

    It will add Access-Control-Allow-Origin '*'. If you want something different, look this page