在react中引入了setupProxy作为代理解决跨域问题,在本地可以做到了转发并访问外部接口,然后在把项目打包之后,放入nginx服务器上,再次请求外部接口,就会出现无法访问的情况,服务器上的报错是403。
PS:接口使用的人比较多,应该不会出现问题
在生产环境,proxy是无效的
建议生产环境使用nginx解决跨域
下边是ant-design-pro里边proxy的说明
/**
* 在生产环境 代理是无法生效的,所以这里没有生产环境的配置
* The agent cannot take effect in the production environment
* so there is no configuration of the production environment
* For details, please see
* https://pro.ant.design/docs/deploy
*/
export default {
dev: {
'/api/': {
target: 'https://preview.pro.ant.design',
changeOrigin: true,
pathRewrite: {
'^': '',
},
},
},
test: {
'/api/': {
target: 'https://preview.pro.ant.design',
changeOrigin: true,
pathRewrite: {
'^': '',
},
},
},
pre: {
'/api/': {
target: 'your pre url',
changeOrigin: true,
pathRewrite: {
'^': '',
},
},
},
};