This commit is contained in:
Sakurasan
2024-11-18 02:37:15 +08:00
parent 653b68c644
commit d5d87a9bb0
2 changed files with 12 additions and 2 deletions

View File

@@ -14,7 +14,6 @@ import (
"os" "os"
"github.com/duke-git/lancet/v2/fileutil" "github.com/duke-git/lancet/v2/fileutil"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/google/uuid" "github.com/google/uuid"
"gorm.io/gorm" "gorm.io/gorm"
@@ -143,6 +142,7 @@ func main() {
} }
port := os.Getenv("PORT") port := os.Getenv("PORT")
r := gin.Default() r := gin.Default()
r.Use(team.CORS())
group := r.Group("/1") group := r.Group("/1")
{ {
group.Use(team.AuthMiddleware()) group.Use(team.AuthMiddleware())
@@ -167,7 +167,7 @@ func main() {
// 初始化用户 // 初始化用户
r.POST("/1/users/init", team.Handleinit) r.POST("/1/users/init", team.Handleinit)
r.Any("/v1/*proxypath", cors.Default(), router.HandleProxy) r.Any("/v1/*proxypath", router.HandleProxy)
// r.POST("/v1/chat/completions", router.HandleProy) // r.POST("/v1/chat/completions", router.HandleProy)
// r.GET("/v1/models", router.HandleProy) // r.GET("/v1/models", router.HandleProy)

View File

@@ -6,6 +6,7 @@ import (
"opencatd-open/store" "opencatd-open/store"
"strings" "strings"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -57,3 +58,12 @@ func AuthMiddleware() gin.HandlerFunc {
c.Next() c.Next()
} }
} }
func CORS() gin.HandlerFunc {
config := cors.DefaultConfig()
config.AllowAllOrigins = true
config.AllowCredentials = true
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
config.AllowHeaders = []string{"*"}
return cors.New(config)
}