Next.js 常见开发问题

2023-06-11 | 4分钟 | yrobot | Next.js,开发,问题,方案

为/api/* 配置跨域

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  async headers() {
    return [
      {
        source: "/api/(.*)",
        headers: [{ key: "Access-Control-Allow-Origin", value: "*" }],
      },
    ];
  },
};

module.exports = nextConfig;