forked from akai/readest
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:
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user