Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#5562 from ChatGPTNextWeb/hotfix-goo…
Browse files Browse the repository at this point in the history
…gle-api

hotfix for `x-goog-api-key`
  • Loading branch information
lloydzhou authored Sep 29, 2024
2 parents f9d6f4f + 5bdf411 commit 452fc86
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/api/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export async function handle(
});
}

const bearToken = req.headers.get("Authorization") ?? "";
const bearToken =
req.headers.get("x-goog-api-key") || req.headers.get("Authorization") || "";
const token = bearToken.trim().replaceAll("Bearer ", "").trim();

const apiKey = token ? token : serverConfig.googleApiKey;
Expand Down Expand Up @@ -92,16 +93,16 @@ async function request(req: NextRequest, apiKey: string) {
10 * 60 * 1000,
);
const fetchUrl = `${baseUrl}${path}${
req?.nextUrl?.searchParams?.get("alt") === "sse" ? "&alt=sse" : ""
req?.nextUrl?.searchParams?.get("alt") === "sse" ? "?alt=sse" : ""
}`;

console.log("[Fetch Url] ", fetchUrl);
const fetchOptions: RequestInit = {
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-store",
"x-google-api-key":
req.headers.get("x-google-api-key") ||
"x-goog-api-key":
req.headers.get("x-goog-api-key") ||
(req.headers.get("Authorization") ?? "").replace("Bearer ", ""),
},
method: req.method,
Expand Down

0 comments on commit 452fc86

Please sign in to comment.