Angular Service Worker-无法加载资源:服务器响应状态为504(网关超时) [英] Angular Service Worker - Failed to load resource: the server responded with a status of 504 (Gateway Timeout)

查看:741
本文介绍了Angular Service Worker-无法加载资源:服务器响应状态为504(网关超时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular-CLI 1.6.6 @ angular / service-worker 5.2.5 我们的 Angular 5.2.5 应用。一切在本地lite服务器以及生产服务器上都可以正常运行,除了在生产环境中弹出一条错误消息:

I am using the Angular-CLI 1.6.6 and @angular/service-worker 5.2.5 in our Angular 5.2.5 app. Everything works fine on the local lite-server, as well as on the production server, except for one error message popping in our production environment:


加载资源失败:服务器响应状态为504
(网关超时)

Failed to load resource: the server responded with a status of 504 (Gateway Timeout)

查看 ngsw-worker.js 脚本,我发现生成上述错误消息的行(以下为2466):

Looking into the ngsw-worker.js script I found the lines (2466 following) where the error message above is generated:

    async safeFetch(req) {
        try {
            return await this.scope.fetch(req);
        }
        catch (err) {
            this.debugger.log(err, `Driver.fetch(${req.url})`);
            return this.adapter.newResponse(null, {
                status: 504,
                statusText: 'Gateway Timeout',
            });
        }
    } 

控制台中的日志记录错误会导致以下错误:

Console logging err in the catch puts out the following error:

    TypeError: Failed to execute 'fetch' on 'ServiceWorkerGlobalScope': 'only-if-cached' can be set only with 'same-origin' mode
        at Driver.safeFetch (ngsw-worker.js:2464)
        at Driver.handleFetch (ngsw-worker.js:1954)
        at <anonymous>

似乎与此问题相关的错误:

An error that seems related to this question: What causes a Failed to execute 'fetch' on 'ServiceWorkerGlobalScope': 'only-if-cached' can be set only with 'same-origin' mode error?

产生此错误的要求是对该应用程序的任何首次访问?

The req that generates this error is any first access to the app:

https://example.com/test/#/connect
https://example.com/test/#/map?token=[accestoken]
...

在应用程序重新加载时不会重复出现此错误。

On app reload the error is not repeated.

有人可以帮我吗?服务工作者的 safeFetch()中是否存在错误(可能支持HashLocationStrategy)?

Can anybody help me out here? Is there a bug in safeFetch() of the service worker (maybe to support HashLocationStrategy)? Do I have to change anything in my config?

推荐答案

从后端禁用ETag标头可以暂时解决此问题。

Disabling ETag header from backend solved this issue temporarily.

这篇关于Angular Service Worker-无法加载资源:服务器响应状态为504(网关超时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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