Gin框架配置CORS后响应未添加跨域头问题求助
Gin框架配置CORS后响应未添加跨域头问题求助
各位大佬好,我现在用Go语言的Gin框架开发接口,遇到了CORS跨域错误。之前在NodeJS项目里碰到类似问题很快就解决了,但这次用Gin怎么都搞不定,实在头疼😩。
我找到了gin-contrib/cors这个包来配置跨域,修改了代码如下:
r := gin.Default() r.Use(cors.New(cors.Config{ AllowOrigins: []string{"http://localhost:5173"}, AllowMethods: []string{"PUT", "PATCH", "POST"}, AllowHeaders: []string{"Origin"}, ExposeHeaders: []string{"Content-Length", "Content-Type"}, AllowFiles: true, AllowCredentials: true, AllowOriginFunc: func(origin string) bool { return origin == "http://localhost:5173" }, }))
但配置完之后,跨域错误还是照样出现,有没有大佬能帮我看看哪里出问题了?
备注:内容来源于stack exchange,提问作者Sushant Dhiman
相关产品推荐
相关产品推荐

