【发布时间】:2019-01-06 03:41:22
【问题描述】:
我有一个 Angular 6 应用程序和 python(django 2.0.6) 后端。 Angular 6 应用程序使用 AWS S3 和 CloudFront 部署。
Angular 6 应用程序使用 websocket 功能。 一切都在本地运行良好,但是当部署 Angular 6 应用程序时,无法通过 websocket 握手请求传递 cookie。 (授权仅通过 cookie 用于 websoket 连接。这是有原因的,不相关。)
Websocket 服务器位于子域:`api.site.com``
我尝试了多种方法在 Angular 6 应用中设置 cookie,例如:
let domain = 'api.site.com'
document.cookie = `Token=${token}; domain=${domain}; path=/`;
document.cookie = `Token=${token}; path=/`;
document.cookie = `Token=${token};
document.cookie = `Token=${token}, domain=${domain}, path=/`;
使用ngx-cookie-service:
this.cookieService.set('Token', token, undefined, '/', 'api.site.com');
this.cookieService.set('Token', token, undefined, '/');
this.cookieService.set('Token', token);
token 是 JWT 令牌。
对于上述所有情况,在部署应用程序时,Token cookie 不会与 websocket 握手一起传递。使用wss 协议。
angular 6 app 在site.com 域下运行(=> api 是一个子域)
Cloudfront 行为设置为传递所有 cookie。
请告知可能的原因。
【问题讨论】:
标签: angular cookies websocket amazon-cloudfront