在react中引入了setupProxy作为代理解决跨域问题,在本地可以做到了转发并访问外部接口,然后在把项目打包之后,放入nginx服务器上,再次请求外部接口,就会出现无法访问的情况,服务器上的报错是403。
PS:接口使用的人比较多,应该不会出现问题
react打包后代理失效
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- 凉城┓.〆 2023-03-06 17:43关注
在生产环境,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: { '^': '', }, }, }, };
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 目详情-五一模拟赛详情页
- ¥15 有了解d3和topogram.js库的吗?有偿请教
- ¥100 任意维数的K均值聚类
- ¥15 stamps做sbas-insar,时序沉降图怎么画
- ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
- ¥15 关于#Java#的问题,如何解决?
- ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
- ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
- ¥15 cmd cl 0x000007b
- ¥20 BAPI_PR_CHANGE how to add account assignment information for service line