浏览器被重定向到服务-worker.js

Browser is redirected to service-worker.js

我正在开发两个独立的项目:一个是 Polymer 带有 Service worker 的应用程序(使用 Polymer CLI 搭建),第二个应用程序是 Spring Boot 带有 Vaadin 及其集成库 Vaadin Spring。两个应用程序都是 运行 localhost:8080

在 SpringBoot 应用程序上,未经身份验证的用户被重定向到 /login。身份验证成功后,用户应该被重定向回 /,而不是被重定向到 url http://localhost:8080/service-worker.js,其中显示默认的 spring 404 页面。当我手动将 url 更改回 / 时,SpringBoot 应用程序再次运行。

我找不到问题的根源(如果是 Polymer 或 SpringBoot+Vaadin)并且每次都清除缓存或手动更改 URL 令人沮丧。

编辑:

我正在使用 Vaadin Spring 提供的默认处理程序 SavedRequestAwareVaadinAuthenticationSuccessHandler。它应该重定向回之前的 URL 或回退 URL /.

@Bean(name = VaadinSharedSecurityConfiguration.VAADIN_AUTHENTICATION_SUCCESS_HANDLER_BEAN)
VaadinAuthenticationSuccessHandler vaadinAuthenticationSuccessHandler(@SuppressWarnings("SpringJavaAutowiringInspection") HttpService httpService, VaadinRedirectStrategy vaadinRedirectStrategy) {
    return new SavedRequestAwareVaadinAuthenticationSuccessHandler(httpService, vaadinRedirectStrategy, "/");
}

我遇到了同样的问题。这是浏览器的事情,你不能从你的应用程序或服务器端注意到。

我通过手动删除 chrome 中本地主机地址的服务工作者解决了 ti。

您可以通过在 chrome -> Tab Resources -> Service Workers
中打开开发者工具来完成 在特定 url 上找到您的服务工作者,例如 http://localhost:8080/login 并将其删除。

另一种方法是使用不同的本地主机(localhost, 127.0.0.1, 127.0.0.2) IP地址来开发聚合物应用程序和Vaadin应用程序。

问题是访问 "service-worker.js" 需要身份验证,因为这个 "service-worker.js" 在每次更改时自动访问并替换会话属性 SPRING_SECURITY_SAVED_REQUEST,一个简单的解决方案是授予 public 访问权限:

 http.authorizeRequests()
        .antMatchers("/service-worker.js").permitAll()
        .antMatchers("/**").fullyAuthenticated().and()

我解决了。 转到 locahost:8080/login -> Inspect (ctr+shift+I) -> Application 选项卡 -> 选择 Service Worker 并取消注册 sw.js 祝你好运!