import type { NextConfig } from "next"; const nextConfig: NextConfig = { reactStrictMode: true, // 局域网/远程设备访问 dev server 时,/_next/* 资源按允许来源放行(Next 15.5+) // 192.168.1.166 = 本机(macOS)LAN IP(前端监听 0.0.0.0:3000);192.168.1.160 = Pi5; // 其它客户端来源按需追加,否则其 /_next/* 请求会被 Next 拒绝。 allowedDevOrigins: ["192.168.1.160", "192.168.1.166", "127.0.0.1", "localhost"], // dev server 同源代理(rewrites)默认 30s 超时(http-proxy),而选股/因子研究等 // 同步后端接口需数十秒(全市场选股实测 ~50s),超过会被代理掐断成 500 // ("Failed to proxy ... socket hang up")。调大至 5 分钟,避免长研究请求被截断。 experimental: { proxyTimeout: 300_000 }, // 同源代理:页面请求 /api/* → 后端 FastAPI(默认 127.0.0.1:8000) // 使任何 IP/域名访问前端都无需 CORS 与硬编码后端地址。 // 后端地址可用环境变量 BACKEND_API_URL 覆盖(如 0.0.0.0 部署到别的机器)。 async rewrites() { const backend = process.env.BACKEND_API_URL ?? "http://127.0.0.1:8000"; return [{ source: "/api/:path*", destination: `${backend}/api/:path*` }]; }, }; export default nextConfig;