import type { NextConfig } from "next"; import { readFileSync, existsSync } from "fs"; import { join } from "path"; // 构建时自动加载 Server Actions 加密密钥,避免 "Failed to find Server Action" 部署错误 if (!process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY) { const keyPath = join(__dirname, "config", "server-actions.key"); if (existsSync(keyPath)) { process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY = readFileSync(keyPath, "utf8").trim(); } } const nextConfig: NextConfig = { // 局域网访问(如手机 192.168.x.x)时允许跨域请求 _next 资源 // 需完全重启 dev 服务(Ctrl+C 后 pnpm dev)后生效 allowedDevOrigins: [ "192.168.41.222", "192.168.41.222:3000", "http://192.168.41.222", "http://192.168.41.222:3000", "http://192.168.41.222:3001", ], }; export default nextConfig;