Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakurasan committed Nov 17, 2024
1 parent 653b68c commit d5d87a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions opencat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"os"

"github.com/duke-git/lancet/v2/fileutil"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"gorm.io/gorm"
Expand Down Expand Up @@ -143,6 +142,7 @@ func main() {
}
port := os.Getenv("PORT")
r := gin.Default()
r.Use(team.CORS())
group := r.Group("/1")
{
group.Use(team.AuthMiddleware())
Expand All @@ -167,7 +167,7 @@ func main() {
// 初始化用户
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.GET("/v1/models", router.HandleProy)
Expand Down
10 changes: 10 additions & 0 deletions pkg/team/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"opencatd-open/store"
"strings"

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -57,3 +58,12 @@ func AuthMiddleware() gin.HandlerFunc {
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)
}

0 comments on commit d5d87a9

Please sign in to comment.