Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CORS in Grails 3.0.1

Tags:

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

like image 768
Luis Vargas Avatar asked Apr 11 '15 23:04

Luis Vargas


People also ask

How do I enable CORS access?

Simply activate the add-on and perform the request. CORS or Cross-Origin Resource Sharing is blocked in modern browsers by default (in JavaScript APIs). Installing this add-on will allow you to unblock this feature.


1 Answers

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

like image 85
Ratata Tata Avatar answered Sep 19 '22 12:09

Ratata Tata