Skip to content

Commit 26ee79f

Browse files
committed
fix options request
1 parent 1e4c90e commit 26ee79f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/diemus/azure-openai-proxy/pkg/openai"
66
"github.com/gin-gonic/gin"
77
"log"
8+
"net/http"
89
"os"
910
)
1011

@@ -29,6 +30,15 @@ func main() {
2930
r := gin.Default()
3031
r.Any("*path", func(c *gin.Context) {
3132
if ProxyMode == "azure" {
33+
// BUGFIX: fix options request, see https://github.com/diemus/azure-openai-proxy/issues/1
34+
if c.Request.Method == http.MethodOptions {
35+
c.Header("Access-Control-Allow-Origin", "*")
36+
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
37+
c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
38+
c.Status(200)
39+
return
40+
}
41+
3242
server := azure.NewOpenAIReverseProxy()
3343
server.ServeHTTP(c.Writer, c.Request)
3444
//BUGFIX: try to fix the difference between azure and openai

pkg/azure/proxy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func init() {
4646
}
4747
if v := os.Getenv("AZURE_OPENAI_TOKEN"); v != "" {
4848
AzureOpenAIToken = v
49+
log.Printf("loading azure api token from env")
4950
}
5051

5152
log.Printf("loading azure api endpoint: %s", AzureOpenAIEndpoint)

0 commit comments

Comments
 (0)