chore: update auth value logic (#3630)

This commit is contained in:
Fred Liang 2023-12-25 10:25:43 +08:00 committed by Hk-Gosuto
parent 4ea2b66e1a
commit 9bfd979b08
1 changed files with 7 additions and 2 deletions

View File

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