Setting serviceWorker url to another relative path does not work #745
-
Moving |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey, @samadadi. Note that moving the worker script changes the scope at which it can intercept requests. I highly recommend reading through this to understand this behavior better. When you move
If your decision to move the worker script is purely aesthetical, consider leaving it at your application's root so it could capture all outgoing requests. If you absolutely must move the worker script, then follow the suggestions from the page I've linked above to configure your application to allow Service Worker to do so. |
Beta Was this translation helpful? Give feedback.
-
I saw |
Beta Was this translation helpful? Give feedback.
Hey, @samadadi.
Note that moving the worker script changes the scope at which it can intercept requests. I highly recommend reading through this to understand this behavior better.
When you move
mockServiceWorker.js
to/mocks
, the worker, and thus MSW, cannot intercept requests that originate from pages other than/mocks/*
(i.e. from the homepage of your application). I can see thehttp://localhost:3000/mocks/mockServiceWorker.js
script loaded successfully, as well as the MSW activation message printed. These two factors mean that MSW has been successfully enabled. The/api/graphql
request is not intercepted because it's performed from the root/
of your application, which is outside of t…