From 5bdf41139917f815143de11a9e04b261666c7707 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Sun, 29 Sep 2024 15:51:28 +0800 Subject: [PATCH] hotfix for `x-goog-api-key` --- app/api/google.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/api/google.ts b/app/api/google.ts index 7d3f08be4d9..707892c33d0 100644 --- a/app/api/google.ts +++ b/app/api/google.ts @@ -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; @@ -92,7 +93,7 @@ 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); @@ -100,8 +101,8 @@ async function request(req: NextRequest, apiKey: string) { 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,