How to enable CORS in Grails 3.0.1

后端 未结 7 1320
有刺的猬
有刺的猬 2021-02-18 22:45

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 thi

7条回答
  •  南旧
    南旧 (楼主)
    2021-02-18 22:53

    You should use grails 3's new Interceptor API. (https://grails.github.io/grails-doc/3.0.x/guide/single.html#interceptors)

    You can create an interceptor with the grails create-interceptor command. For a CORS Interceptor I would use the after() method of this Interceptor, and set it up to match all requests (or just the requests you need). You can use the response object in this method, so setting the headers should be similar to the case described in the Spring documentation.

提交回复
热议问题