Jelajahi Sumber

fix: return bearer header when using openai

Fred Liang 1 tahun lalu
induk
melakukan
19137b79bc
1 mengubah file dengan 10 tambahan dan 3 penghapusan
  1. 10 3
      app/api/common.ts

+ 10 - 3
app/api/common.ts

@@ -9,9 +9,16 @@ const serverConfig = getServerSideConfig();
 export async function requestOpenai(req: NextRequest) {
   const controller = new AbortController();
 
-  const authValue =
-    req.headers.get("Authorization")?.trim().replaceAll("Bearer ", "").trim() ??
-    "";
+  if (serverConfig.isAzure) {
+    const authValue =
+      req.headers
+        .get("Authorization")
+        ?.trim()
+        .replaceAll("Bearer ", "")
+        .trim() ?? "";
+  } else {
+    const authValue = req.headers.get("Authorization") ?? "";
+  }
   const authHeaderName = serverConfig.isAzure ? "api-key" : "Authorization";
 
   let path = `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll(