feat: support set api key from client side

This commit is contained in:
Fred Liang
2023-12-24 03:44:13 +08:00
parent 4169431f2c
commit 20f2f61349
5 changed files with 16 additions and 4 deletions

View File

@@ -43,7 +43,9 @@ async function handle(
10 * 60 * 1000,
);
const key = req.nextUrl.searchParams.get("key") ?? serverConfig.googleApiKey;
const bearToken = req.headers.get("Authorization") ?? "";
const token = bearToken.trim().replaceAll("Bearer ", "").trim();
const key = token ?? serverConfig.googleApiKey;
const fetchUrl = `${baseUrl}/${path}?key=${key}`;
const fetchOptions: RequestInit = {