gongxiangp2/app/layout.tsx
2026-07-07 14:36:52 +08:00

59 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { Metadata } from 'next'
import './globals.css'
import Providers from './providers'
import { prisma } from '@/lib/prisma'
async function getSystemSettings() {
try {
// 直接从数据库查询,避免网络请求超时问题
const settings = await prisma.systemSettings.findFirst({
select: {
siteName: true,
}
})
return settings
} catch (error) {
console.error('Failed to fetch system settings:', error)
}
return null
}
export async function generateMetadata(): Promise<Metadata> {
const settings = await getSystemSettings()
return {
title: settings?.siteName || '由壹点3D素材',
description: '3D素材分享平台',
icons: {
icon: '/api/favicon',
shortcut: '/api/favicon',
apple: '/api/favicon',
},
}
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="zh-CN">
<head>
{/* 禁用浏览器缓存,确保用户总是获取最新代码 */}
<meta httpEquiv="Cache-Control" content="no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0" />
<meta httpEquiv="Pragma" content="no-cache" />
<meta httpEquiv="Expires" content="0" />
{/* 允许 blob URL 在 HTTP 页面上使用(解决 HTTPS 警告) */}
{/* 注意:frame-ancestors 只能通过 HTTP 响应头设置,不能通过 meta 标签 */}
<meta httpEquiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' blob: data: http: https: ws: wss:; img-src 'self' 'unsafe-inline' blob: data: http: https:; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: https://g.alicdn.com; style-src 'self' 'unsafe-inline'; connect-src 'self' blob: data: http: https: ws: wss:; media-src 'self' blob: data: http: https:; font-src 'self' data: http: https:; object-src 'none'; base-uri 'self'; form-action 'self';" />
</head>
<body className="font-sans antialiased">
<Providers>
{children}
</Providers>
</body>
</html>
)
}