下一步.js - 请求的资源上不存在"访问控制允许源"标头



我继承了刚刚从React迁移到的Next应用程序。

当访问从AWS服务器获取数据的页面时,我会得到一个CORS错误-

Access to XMLHttpRequest at 'https://**************' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

next.config.js中,我添加了以下内容来设置代理-

async rewrites() {
return [
{
source: '/api/:path*',
destination: '*********'
}
]
},

重新启动服务器后,错误仍然存在。

我还可以尝试什么,以便在不出现CORS错误的情况下获取数据?

您应该首先检查aws侧。如果使用apigateway为页面获取的数据提供服务,则apigateway具有cors的设置。这是rest api模式。

相关内容

最新更新