Fix 500 Internal Server Error: Add error handling for D1 database access in Cloudflare Pages

This commit is contained in:
katelya
2025-09-05 16:05:52 +08:00
parent 142c780b50
commit 07cdaafcb2
3 changed files with 47 additions and 15 deletions
+13 -6
View File
@@ -14,12 +14,19 @@ const inter = Inter({ subsets: ['latin'] });
// 动态生成 metadata,支持配置更新后的标题变化
export async function generateMetadata(): Promise<Metadata> {
let siteName = process.env.SITE_NAME || 'KatelyaTV';
if (
process.env.NEXT_PUBLIC_STORAGE_TYPE !== 'd1' &&
process.env.NEXT_PUBLIC_STORAGE_TYPE !== 'upstash'
) {
const config = await getConfig();
siteName = config.SiteConfig.SiteName;
try {
// 只有在非 d1 和 upstash 存储类型时才尝试获取配置
if (
process.env.NEXT_PUBLIC_STORAGE_TYPE !== 'd1' &&
process.env.NEXT_PUBLIC_STORAGE_TYPE !== 'upstash'
) {
const config = await getConfig();
siteName = config.SiteConfig.SiteName;
}
} catch (error) {
// 如果配置获取失败,使用默认站点名称
// siteName 已经有默认值,不需要额外处理
}
return {