fix: fix server token fetch policy

This commit is contained in:
Fred Liang 2023-12-24 03:57:30 +08:00
parent 20f2f61349
commit 7d9a2132cb
No known key found for this signature in database
GPG Key ID: 4DABDA85EF70EC71

View File

@ -45,7 +45,20 @@ async function handle(
const bearToken = req.headers.get("Authorization") ?? "";
const token = bearToken.trim().replaceAll("Bearer ", "").trim();
const key = token ?? serverConfig.googleApiKey;
const key = token ? token : serverConfig.googleApiKey;
if (!key) {
return NextResponse.json(
{
error: true,
message: `missing GOOGLE_API_KEY in server env vars`,
},
{
status: 401,
},
);
}
const fetchUrl = `${baseUrl}/${path}?key=${key}`;
const fetchOptions: RequestInit = {