我正在try 对我的端点(http:localhost:8080/orders?page=10&;pageSize=10)进行api调用,这是在Go with the Gin框架中编写的.我的前端是一款Nextjs应用程序.我收到"原始‘http://localhost:3000’已被CORS策略阻止:请求的资源上不存在‘Access-Control-Allow-Origin’标头".
我试过https://github.com/gin-contrib/cors和https://github.com/rs/cors.我也try 手动设置标题,但我似乎不能使它工作.
现在,我的代码如下所示:
func Init(init *configs.Initialization) *gin.Engine {
router := gin.New()
router.Use(cors.Default())
router.Use(gin.Logger())
router.Use(gin.Recovery())
orders := router.Group("/orders")
{
orders.GET("/", init.OrderController.GetOrders)
orders.GET("/:orderID", init.OrderController.GetOrder)
}
return router
}
CORS是从"githorb.com/gin-conrib/cors"上进口的.
任何帮助都是感激的,我已经try 了每一个答案,我已经找到了,但没有运气.