From 43d9db8f2b553778c67e9d595bdd8d85d89fdf68 Mon Sep 17 00:00:00 2001 From: cobb Date: Wed, 13 Apr 2022 19:42:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E5=9F=9F=E9=97=AE=E9=A2=98=EF=BC=81?= =?UTF-8?q?=EF=BC=81=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index b648231..ca0d0d3 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( func main() { r := gin.Default() + r.Use(Cors()) r.POST("/sql", func(c *gin.Context) { var req struct { Content string `json:"content"` @@ -32,15 +33,14 @@ func main() { c.String(http.StatusOK, string(res)) }) r.StaticFS("/", http.FS(web.Static)) - r.Use(Cors()) r.Run(":8000") } func Cors() gin.HandlerFunc { return cors.New(cors.Config{ - AllowOrigins: []string{"*"}, - AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"}, + AllowAllOrigins: true, AllowCredentials: true, + AllowHeaders: []string{"*"}, MaxAge: time.Second * time.Duration(7200), }) }