问题描述
限时送ChatGPT账号..我正在使用 grails 开发 Rest Api.它正在 localhost:8080 上运行.当我打电话给邮递员时,它用 json 响应.我想使用这些数据并在我在其他域上运行的网页上执行 CRUD 操作.当我尝试调用用 grails 编写的 RESTAPI 时,由于 Access-Control-Allow-Origin,浏览器无法获得响应.那么如何在我的 REST API 中启用 CORS 功能,以便任何人都可以从不同的域访问.
I am developing Rest Api using grails. It is working on localhost:8080. when I am calling with POSTMAN it responded with json. I want to use this data and also perform CRUD operation on my web page which is running on other domain. When I am trying to call RESTAPI which is written in grails, the browser is not able to get a response due to Access-Control-Allow-Origin. So how to enable CORS functionality in my REST API, So anyone can access from a different domain.
推荐答案
如果您使用的是 Grails 3.2.1 或更高版本,它带有内置的 CORS 支持.
If you are using Grails 3.2.1 or higher, it comes with CORS support built in.
在您的 application.yml
中,添加以下内容:
In your application.yml
, add the following:
grails:
cors:
enabled: true
参见 http://docs.grails/latest/guide/Introduction.html#whatsNewCors 了解更多详情.
See http://docs.grails/latest/guide/introduction.html#whatsNewCors for further details.
这篇关于如何将 CORS 与 grails rest API 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论