import { getConfig } from '../data/config.js'; async function handleDebug(request, env) { try { const url = new URL(request.url); const config = await getConfig(env); const debugInfo = { timestamp: new Date().toISOString(), pathname: url.pathname, kvBinding: !!env.SUBSCRIPTIONS_KV, configExists: !!config, adminUsername: config.ADMIN_USERNAME, hasJwtSecret: !!config.JWT_SECRET, jwtSecretLength: config.JWT_SECRET ? config.JWT_SECRET.length : 0 }; return new Response(` 调试信息

系统调试信息

基本信息

时间: ${debugInfo.timestamp}

路径: ${debugInfo.pathname}

KV绑定: ${debugInfo.kvBinding ? '✓' : '✗'}

配置信息

配置存在: ${debugInfo.configExists ? '✓' : '✗'}

管理员用户名: ${String(debugInfo.adminUsername || '').replace(//g, '>')}

JWT密钥: ${debugInfo.hasJwtSecret ? '✓' : '✗'} (长度: ${debugInfo.jwtSecretLength})

解决方案

1. 确保KV命名空间已正确绑定为 SUBSCRIPTIONS_KV

2. 尝试访问 / 进行登录

3. 如果仍有问题,请检查Cloudflare Workers日志

`, { headers: { 'Content-Type': 'text/html; charset=utf-8' } }); } catch (error) { return new Response(`调试页面错误: ${error.message}`, { status: 500, headers: { 'Content-Type': 'text/plain; charset=utf-8' } }); } } export { handleDebug };