Skip to content

Next.js next.config.ts

ts
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  // 图片域名白名单
  images: { remotePatterns: [{ protocol: 'https', hostname: 'cdn.example.com' }] },
  // 重定向
  async redirects() { return [{ source: '/old', destination: '/new', permanent: true }] },
  // 重写(代理)
  async rewrites() { return [{ source: '/api/:path*', destination: 'http://backend:3000/:path*' }] },
  // 跨域
  async headers() { return [{ source: '/api/:path*', headers: [{ key: 'Access-Control-Allow-Origin', value: '*' }] }] },
  // 环境变量
  env: { CUSTOM_KEY: 'value' },
}

export default nextConfig