Skip to content

Commit 785a739

Browse files
authored
Merge pull request #579 from KortanZ/main
fix: accept openai x-stainless-* header to fix CORS error
2 parents a817caf + ab14df0 commit 785a739

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • backend/internal/server/middleware

backend/internal/server/middleware/cors.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ func CORS(cfg config.CORSConfig) gin.HandlerFunc {
7070
}
7171
}
7272

73-
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, X-API-Key")
73+
allowHeaders := []string{"Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", "accept", "origin", "Cache-Control", "X-Requested-With", "X-API-Key"}
74+
75+
// openai node sdk
76+
openAIProperties := []string{"lang", "package-version", "os", "arch", "retry-count", "runtime", "runtime-version", "async", "helper-method", "poll-helper", "custom-poll-interval", "timeout"}
77+
for _, prop := range openAIProperties {
78+
allowHeaders = append(allowHeaders, "x-stainless-"+prop)
79+
}
80+
81+
c.Writer.Header().Set("Access-Control-Allow-Headers", strings.Join(allowHeaders, ", "))
7482
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, DELETE, PATCH")
7583

7684
// 处理预检请求

0 commit comments

Comments
 (0)