ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.45k stars 8.14k forks source link

可否支持类似这样的websocket的proxy相关配置 #6813

Closed wzlee closed 4 years ago

wzlee commented 4 years ago

🥰 需求描述

项目中遇到需要使用websocket的组件,但需要独立配置url,但无法使用config.ts中的proxy配置


let wsSourceUrl = 'http://127.0.0.1:8080/ws/app/';
<SockJsClient
            url={wsSourceUrl}
            topics={[
              `/salt/beacon/${current.id}/memusage`,
              `/salt/beacon/${current.id}/network_info`,
              `/salt/beacon/${current.id}/diskusage`,
              `/salt/beacon/${current.id}/cpuusage`,
            ]}
            onMessage={this.onBeaconMessageReceive}
            onConnect={this.onBeaconConnected}
            onDisconnect={this.onBeaconDisconnected}
            debug={false}
          />

### 🧐 解决方案
期望可以在config中全局配置这个url并且支持proxy全局代理
domeafavour commented 4 years ago

支持websocket代理啊:

// config/proxy.js
export default {
  dev: {
    '/api/': {
      target: 'http://localhost:8888',
      changeOrigin: true,
      secure: false,
      pathRewrite: {
        '^/api': '/api',
      },
    },
    // websocket代理
    '/ws/': {
      target: 'ws://localhost:8889',
      ws: true,
      logLevel: 'debug',
      secure: false,
      pathRewrite: {
        '^/ws': '',
      },
    },
  },
}
sayPink commented 4 years ago

支持websocket代理啊:

// config / proxy.js 
导出 默认值 { 
  dev:{ 
    '/ api /':{ 
      目标:'http:// localhost:8888' ,
      changeOrigin:true ,
      secure:false ,
      pathRewrite:{ 
        '^ / api':' / api' ,
      } ,
    } ,
    // websocket代理
    '/ ws /':{ 
      target:'ws:// localhost:8889' ,
      ws:true ,
      logLevel:'debug',
      secure:false ,
      pathRewrite:{ 
        '^ / ws':'' ,
      } ,
    } ,
  } ,
}

老哥 这样配置完成后,应该怎么使用啊,在线求方案

domeafavour commented 4 years ago

支持websocket代理啊:

// config / proxy.js 
导出 默认值 { 
  dev:{ 
    '/ api /':{ 
      目标:'http:// localhost:8888' ,
      changeOrigin:true ,
      secure:false ,
      pathRewrite:{ 
        '^ / api':' / api' ,
      } ,
    } ,
    // websocket代理
    '/ ws /':{ 
      target:'ws:// localhost:8889' ,
      ws:true ,
      logLevel:'debug',
      secure:false ,
      pathRewrite:{ 
        '^ / ws':'' ,
      } ,
    } ,
  } ,
}

老哥 这样配置完成后,应该怎么使用啊,在线求方案

参考一下这个吧 https://blog.csdn.net/u013897323/article/details/106330388 协议、地址、端口动态获取一下,然后拼接成你的wsSourceUrl

sayPink commented 4 years ago

按照她这样写 好像链接都建立不上 

------------------ 原始邮件 ------------------ 发件人: "ant-design/ant-design-pro" <notifications@github.com>; 发送时间: 2020年9月1日(星期二) 晚上6:33 收件人: "ant-design/ant-design-pro"<ant-design-pro@noreply.github.com>; 抄送: "S"<461377096@qq.com>;"Comment"<comment@noreply.github.com>; 主题: Re: [ant-design/ant-design-pro] 可否支持类似这样的websocket的proxy相关配置 (#6813)

支持websocket代理啊: // config / proxy.js 导出 默认值 { dev:{ '/ api /':{ 目标:'http:// localhost:8888' , changeOrigin:true , secure:false , pathRewrite:{ '^ / api':' / api' , } , } , // websocket代理 '/ ws /':{ target:'ws:// localhost:8889' , ws:true , logLevel:'debug', secure:false , pathRewrite:{ '^ / ws':'' , } , } , } , }

老哥 这样配置完成后,应该怎么使用啊,在线求方案

参考一下这个吧 https://blog.csdn.net/u013897323/article/details/106330388 协议、地址、端口动态获取一下,然后拼接成你的wsSourceUrl

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

domeafavour commented 4 years ago

@sayPink 生成的链接能贴一下吗

sayPink commented 4 years ago

这个是生成的链接ws://localhost:8000/ws/admin/ws/conn

然后我代理配置是这么写

老哥能加你个联系方式吗

------------------ 原始邮件 ------------------ 发件人: "ant-design/ant-design-pro" <notifications@github.com>; 发送时间: 2020年9月1日(星期二) 晚上7:37 收件人: "ant-design/ant-design-pro"<ant-design-pro@noreply.github.com>; 抄送: "S"<461377096@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [ant-design/ant-design-pro] 可否支持类似这样的websocket的proxy相关配置 (#6813)

@sayPink 生成的链接能贴一下吗

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

sayPink commented 4 years ago

感谢老哥, 已经找到问题  是我代理的时候  位置摆放错了,感谢老哥万忙之中抽空解答 谢谢 ------------------ 原始邮件 ------------------ 发件人: "ant-design/ant-design-pro" <notifications@github.com>; 发送时间: 2020年9月1日(星期二) 晚上7:37 收件人: "ant-design/ant-design-pro"<ant-design-pro@noreply.github.com>; 抄送: "S"<461377096@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [ant-design/ant-design-pro] 可否支持类似这样的websocket的proxy相关配置 (#6813)

@sayPink 生成的链接能贴一下吗

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

kgloveyou commented 2 years ago

感谢老哥, 已经找到问题  是我代理的时候  位置摆放错了,感谢老哥万忙之中抽空解答 谢谢 ------------------ 原始邮件 ------------------ 发件人: "ant-design/ant-design-pro" <notifications@github.com>; 发送时间: 2020年9月1日(星期二) 晚上7:37 收件人: "ant-design/ant-design-pro"<ant-design-pro@noreply.github.com>; 抄送: "S"<461377096@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [ant-design/ant-design-pro] 可否支持类似这样的websocket的proxy相关配置 (#6813) @sayPink 生成的链接能贴一下吗 — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

确定可以?能贴下代码吗