NextJS App Route API 跨域的解决方案
next.config.js 里配置/** @type {import('next').NextConfig} */
const nextConfig = {
async headers() {
return [
{
source: "/api/(.*)",
headers: [
{
key: "Access-Control-Allow-Origin",
value: "*",
},
{
key: "Access-Control-Allow-Methods",
value: "GET, POST, PUT, DELETE, OPTIONS",
},
{
key: "Access-Control-Allow-Headers",
value: "Content-Type, Authorization",
},
],
},
];
},
};
module.exports = nextConfig
参考自:https://codingwithmanny.medium.com/3-ways-to-configure-cors-for-nextjs-13-app-router-api-route-handlers-427e10929818
页:
[1]