【问题标题】:How to access aws websocket through CloudFront如何通过 CloudFront 访问 aws websocket
【发布时间】:2021-08-12 11:49:49
【问题描述】:

我正在关注这个 url 来设置云前端来源。 https://nickzamosenchuk.medium.com/configure-amazon-cloudfront-cdn-for-websocket-connection-43c44b3f877c 如何通过 Angular 应用程序连接 WebSocket。? 我尝试了 2 种方法,但无法连接。

  let data = this.httpClient.get('https://<id>.cloudfront.net/dev').subscribe(datas => {
      console.log(datas);
    });

this.socket = webSocket('wss://<id>.cloudfront.net/dev');

angular中连接WebSocket的方式是什么?

【问题讨论】:

    标签: angular amazon-web-services websocket amazon-cloudfront


    【解决方案1】:

    是的,有办法,例如:

    import { Injectable } from '@angular/core';
    import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
    
    @Injectable({
      providedIn: 'root'
    })
    export class WebsocketExampleService {
    
      readonly url = "(wss|https)://<id>.cloudfront.net/";
    
      subject: WebSocketSubject<any>;
    
      constructor() {
        this.subject = webSocket({
          url: this.url,
          deserializer: msg => msg
        });
      }
    }
    

    【讨论】:

    • 仍然无法连接到 WebSocket @YaakovHatam
    • 错误是什么?您在浏览器控制台中看到了什么? @user8057332
    • 我没有收到任何控制台错误,但它没有击中 CloudFront。我们需要 CloudFront 源中的任何更新吗?
    猜你喜欢
    • 1970-01-01
    • 2022-06-11
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 2017-05-10
    • 1970-01-01
    • 2016-04-05
    • 2012-05-07
    相关资源
    最近更新 更多