Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser is redirected to service-worker.js

I'm developing two separate projects: one is Polymer app with Service worker(scaffolded with Polymer CLI) and second app is Spring Boot with Vaadin and its itegration library Vaadin Spring. Both applications are running on localhost:8080.

On SpringBoot app, non-authenticated user is redirected to /login. After successful authentication user should be redirected back to /, but instead is redirected to url http://localhost:8080/service-worker.js, where is displayed default spring 404 page. When I manually change url back to /, SpringBoot app is working again.

  • this behavior occured after I was working on Polymer app and switched to SpringBoot
  • tested on Chrome and Firefox
  • clearing browser cache helps
  • Vaadin is also using hashbang

I can't find source of the problem (if is it Polymer or SpringBoot+Vaadin) and clearing cache or manually changing URL every time is frustrating.

EDIT:

I'm using default handler SavedRequestAwareVaadinAuthenticationSuccessHandler provided by Vaadin Spring. It should redirect back to previous URL or to fallback URL /.

@Bean(name = VaadinSharedSecurityConfiguration.VAADIN_AUTHENTICATION_SUCCESS_HANDLER_BEAN)
VaadinAuthenticationSuccessHandler vaadinAuthenticationSuccessHandler(@SuppressWarnings("SpringJavaAutowiringInspection") HttpService httpService, VaadinRedirectStrategy vaadinRedirectStrategy) {
    return new SavedRequestAwareVaadinAuthenticationSuccessHandler(httpService, vaadinRedirectStrategy, "/");
}
like image 618
Loucher Avatar asked Jun 20 '16 09:06

Loucher


2 Answers

I Soleved it. Go to locahost:8080/login -> Inspect (ctr+shift+I) -> Application tab -> choose Service Worker and unregister sw.js Good luck!

like image 177
Nguyen Tung Avatar answered Jan 03 '23 22:01

Nguyen Tung


I had the same problem. This is a browser thing, and you can't do noting from your application or on server side.

I solved ti by deleting service worker for localhost adress in chrome manually.

You can do it by opening developer tools in chrome -> Tab Resources -> Service Workers
Find your service worker on specific url, for example http://localhost:8080/login and delete it.

Another alternative is to use different localhost (localhost, 127.0.0.1, 127.0.0.2) IP addresses for developing polymer application and Vaadin application.

like image 33
Slavus Avatar answered Jan 03 '23 22:01

Slavus