From 4f698be0a59c74e07c09ee05009d4aef2ae7f4c6 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 25 May 2026 16:29:07 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=20=E6=9B=B4=E6=96=B0=20COR?= =?UTF-8?q?S=20=E9=85=8D=E7=BD=AE=E4=BB=A5=E6=94=AF=E6=8C=81=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E6=BA=90=E5=92=8C=E5=87=AD=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openflare_server/middleware/cors.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/openflare_server/middleware/cors.go b/openflare_server/middleware/cors.go index 70f3d404..9933d552 100644 --- a/openflare_server/middleware/cors.go +++ b/openflare_server/middleware/cors.go @@ -1,12 +1,26 @@ package middleware import ( + "openflare/common" + "strings" + "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" ) func CORS() gin.HandlerFunc { config := cors.DefaultConfig() - config.AllowOrigins = []string{"https://openflare.vercel.app", "http://localhost:3000"} + config.AllowCredentials = true + config.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Authorization", "X-Agent-Token", "Accept"} + config.AllowOriginFunc = func(origin string) bool { + serverAddr := strings.TrimRight(common.ServerAddress, "/") + if serverAddr == "" { + return true + } + if origin == serverAddr { + return true + } + return false + } return cors.New(config) }