fix(translation): handle missing Cloudflare context on non-Cloudflare deployments (e.g., Vercel) (#3433)

* fix(translation): handle missing Cloudflare context on non-Cloudflare deployments (e.g., Vercel)

* Simplify error handling for Cloudflare context

---------

Co-authored-by: Huang Xin <chrox.huang@gmail.com>
This commit is contained in:
bfcs
2026-03-01 23:40:45 +08:00
committed by GitHub
parent bf5805910d
commit 152a95941a
@@ -83,7 +83,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return res.status(405).json({ error: 'Method not allowed' });
}
const env = (getCloudflareContext().env || {}) as CloudflareEnv;
let env: Partial<CloudflareEnv> = {};
try {
env = (getCloudflareContext().env || {}) as CloudflareEnv;
} catch {
console.warn('Cloudflare context is not available. Skipping KV cache.');
}
const hasKVCache = !!env['TRANSLATIONS_KV'];
const { user, token } = await validateUserAndToken(req.headers['authorization']);