Skip to content

Commit d5d87a9

Browse files
committed
up
1 parent 653b68c commit d5d87a9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

opencat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"os"
1515

1616
"github.com/duke-git/lancet/v2/fileutil"
17-
"github.com/gin-contrib/cors"
1817
"github.com/gin-gonic/gin"
1918
"github.com/google/uuid"
2019
"gorm.io/gorm"
@@ -143,6 +142,7 @@ func main() {
143142
}
144143
port := os.Getenv("PORT")
145144
r := gin.Default()
145+
r.Use(team.CORS())
146146
group := r.Group("/1")
147147
{
148148
group.Use(team.AuthMiddleware())
@@ -167,7 +167,7 @@ func main() {
167167
// 初始化用户
168168
r.POST("/1/users/init", team.Handleinit)
169169

170-
r.Any("/v1/*proxypath", cors.Default(), router.HandleProxy)
170+
r.Any("/v1/*proxypath", router.HandleProxy)
171171

172172
// r.POST("/v1/chat/completions", router.HandleProy)
173173
// r.GET("/v1/models", router.HandleProy)

pkg/team/middleware.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"opencatd-open/store"
77
"strings"
88

9+
"github.com/gin-contrib/cors"
910
"github.com/gin-gonic/gin"
1011
)
1112

@@ -57,3 +58,12 @@ func AuthMiddleware() gin.HandlerFunc {
5758
c.Next()
5859
}
5960
}
61+
62+
func CORS() gin.HandlerFunc {
63+
config := cors.DefaultConfig()
64+
config.AllowAllOrigins = true
65+
config.AllowCredentials = true
66+
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
67+
config.AllowHeaders = []string{"*"}
68+
return cors.New(config)
69+
}

0 commit comments

Comments
 (0)