import type { NextConfig } from "next"; // 后端地址:开发环境兜底 localhost:3001,生产部署必须显式配置 BACKEND_URL const API_TARGET = process.env.BACKEND_URL || process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001"; const nextConfig: NextConfig = { images: { minimumCacheTTL: 14400, // 4 小时 remotePatterns: [ { protocol: "http", hostname: "localhost" }, ], }, async rewrites() { return [ { source: "/api/:path*", destination: `${API_TARGET}/api/:path*`, }, // 用户上传文件(头像等,全部 WebP) { source: "/uploads/:path*", destination: `${API_TARGET}/uploads/:path*`, }, ]; }, }; export default nextConfig;