question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular Service worker incorrectly intercepting http redirects (302)

See original GitHub issue

Hello,

i work on with angular pwa project with spring-boot back end.

In my project, i am using Angular and Spring boot. My service worker is generating by Angular when i build my project.

I use external service (auth2) and my back-end redirecting to login page when session times out. This works perfectly fine without the service worker enabled, however with the service worker this fails.

To my observation, the mode of the Request is changed from navigate to cors. i see that in request headers

Without SW:

Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate

With SW:

Sec-Fetch-Dest: empty Sec-Fetch-Mode: cors

When active service worker, i have this exception :

Access to fetch at 'https://authentication-url.com/...' (redirected from 'https://my-w ebsite.com/file-request.json') from origin 'https://my-website.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I tried adding ngsw-bypass=true query param to the redirect, but that did not help.

Can you help me ? I search on web but i found nothing on this problem with Angular service worker.

πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:28 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
gkalpakcommented, Jul 31, 2020

So, it sounds you like all three options 😁

What I like about the 3rd oprion is that it is more generic. I would like to try that first (unless we find out it has shortcomings while working on it). (This is also likely the most straight forward to implement, because the association between the requested resources and their cache is clearly defined.)

if it’s good β€œfirst contribution” issue

SW issues are generally not good first issues, because SW is quite different than other front-end code people are used working on. (It’s a little like a server and is very powerful (i.e. even a small change in behavior can significantly impact apps).

But you already seems to have a good grasp of SWs (and @angular/service-worker in particular), so you might want to give it a go πŸ˜ƒ

(Truth be told, this is probably going to be somewhat more complicated than expected.)

2reactions
klemenoslajcommented, Jul 23, 2020

This is the exact problem I was facing as well before and opened two issues:

Hope this can help us moving this issue forward.


I think the reproduction should be possible with the minimal setup just creating a dummy redirect with any server while having Angular Service Worker enabled.


@gkalpak your initial thoughts on the matter were the following:

I feel like this is too specific a usecase (and one that doesn’t fit very well with SW caching) to be worth supporting in @angular/service-worker.

Personally, I would consider redirecting to login from the client (subject to whether the browser is online or not).

If your stance on this issue has changed that would be really great. If not we do have a client redirect as a workaround. I am slightly surprised that only a handful of people hit this problem, considering http redirect is an valid solution for a wide range of problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Service worker incorrectly intercepting http redirects ...
I use external service (auth2) and my back-end redirecting to login page when session times out. This works perfectly fine without the service...
Read more >
302 Found - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 302 Found redirect status response code indicates that the resource requested has been temporarily moved ...
Read more >
Angular Service Worker Request Fails - ADocLib
Ask questionsAngular Service worker incorrectly intercepting http redirects (302). Hello,. i work on with angular pwa project with spring-boot back end.
Read more >
Safari Technology Preview Release Notes - Apple Developer
Fixed an issue where browser.tabs sometimes returned an incorrect URL for pinned tabs. Bug Fixes. Fixed the Share Menu when sharing an image...
Read more >
Unable to add CORS support to spring boot data jpa-Springboot
Coding example for the question Unable to add CORS support to spring boot data ... Angular Service worker incorrectly intercepting http redirects (302)Β ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found