Angular CLI代理WSS [英] Angular CLI proxy wss

查看:95
本文介绍了Angular CLI代理WSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何代理WebSocket请求?

How do I proxy a WebSocket request?

我尝试过:

new WebSocket('/wss/api/v3/users/websocket')

代理:

"/wss/*" : {
  "target" : "wss://someurl.com:443/",
  "secure" : false,
  "ws" : true,
  "wss": true
}

但这给了我: Failed to construct 'WebSocket': The URL '/wss/api/v3/users/websocket' is invalid.

接下来我尝试了

new WebSocket('wss://wss/api/v3/users/websocket')

代理:

"*wss/*" : {
  "target" : "someurl.com:443/",
  "secure" : false,
  "ws" : true,
  "wss": true
}

但这给了我:websocket.provider.ts:20 WebSocket connection to 'wss://wss/api/v3/users/websocket' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED

我该如何代理Websocket?

How do i proxy a websocket?

推荐答案

失败,因为new WebSocker(url)需要完整的URL才能工作.

It's failing because new WebSocker(url)requires a full url to work.

new WebSocket('wss://localhost:3000/wss/api/v3/users/websocket');

我将在angular-clis environment.ts文件中使用应用程序的基本URL进行设置,并用它连接一个字符串.

I would have a setting in angular-clis environment.ts file with the base url for the app, and concat a string with it.

这篇关于Angular CLI代理WSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆