Angular 8 PWA 应用程序将 Server-Sent 事件永远置于挂起状态
Angular 8 PWA application puts Server-Sent events in pending state forever
似乎只有在 Angular 8 中为生产环境编译应用程序时才会导致浏览器从服务器接收 SSE 事件时出现问题。
如果我 运行 应用程序处于开发模式(只需使用 ng serve
),事情就会按预期进行。所以我最初的想法是 PWA 在某种程度上是问题的根源。
我已经尝试在 ngsw-config.json
中排除 api /v1/events
上的缓存,但没有区别:
{
"name":"api",
"urls": ["/api/v1/**"],
"cacheConfig": {
"maxSize": 0,
"maxAge": "0u",
"strategy": "freshness"
}
}
有没有人遇到过类似的问题并妥善解决了?
我想我明白了。我只是向我的 API /v1/events
添加了一个查询参数来绕过服务工作者:/v1/events?ngsw-bypass=true
.
上找到了答案
In some cases, you may want to bypass the service worker entirely and let the browser handle the request instead. An example is when you rely on a feature that is currently not supported in service workers (e.g. reporting progress on uploaded files). To bypass the service worker you can set ngsw-bypass as a request header, or as a query parameter. (The value of the header or query parameter is ignored and can be empty or omitted.)
似乎只有在 Angular 8 中为生产环境编译应用程序时才会导致浏览器从服务器接收 SSE 事件时出现问题。
如果我 运行 应用程序处于开发模式(只需使用 ng serve
),事情就会按预期进行。所以我最初的想法是 PWA 在某种程度上是问题的根源。
我已经尝试在 ngsw-config.json
中排除 api /v1/events
上的缓存,但没有区别:
{
"name":"api",
"urls": ["/api/v1/**"],
"cacheConfig": {
"maxSize": 0,
"maxAge": "0u",
"strategy": "freshness"
}
}
有没有人遇到过类似的问题并妥善解决了?
我想我明白了。我只是向我的 API /v1/events
添加了一个查询参数来绕过服务工作者:/v1/events?ngsw-bypass=true
.
In some cases, you may want to bypass the service worker entirely and let the browser handle the request instead. An example is when you rely on a feature that is currently not supported in service workers (e.g. reporting progress on uploaded files). To bypass the service worker you can set ngsw-bypass as a request header, or as a query parameter. (The value of the header or query parameter is ignored and can be empty or omitted.)