chore: update auth value logic (#3630)

This commit is contained in:
Fred Liang 2023-12-25 10:25:43 +08:00 committed by GitHub
parent a4cb859472
commit 422d70d928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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