信息发布→ 登录 注册 退出

JS跨域解决方案react配置反向代理

发布时间:2026-01-11

点击量:

跨域解决方案  

jsonp(模拟get)

CORS(跨域资源共享)

代理

iframe

postMessage

window.name

WebSocket

react的代理实现跨域

在配置在src/setupProxy.js文件,并通过npm安装http-proxy-middleware,代理中间件模块

创建 src/setupProxy.js

安装模块

npm i -S http-proxy-middleware

  

const {createProxyMiddleware: proxy} = require('http-proxy-middleware')
module.exports = app => {
  app.use('/api', proxy({
    target: 'http://localhost',
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''
    }
  }))
}

 

以上就是JS跨域解决方案react配置反向代理的详细内容,更多关于react配置反向代理的资料请关注其它相关文章!

在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!