Is there a way to submit edits to the website documentation?
See original GitHub issueIs your feature request related to a problem? Please describe.
When I load my app at a route other than the root, MSW would fail to load the service worker. For example, if I load my app from this URL http://localhost:3000/customers/2dd641c3-4069-424e-ad3d-8b2563358dd8
, I get the following error.
[MSW] Failed to register Service Worker (./mockServiceWorker.js). DOMException: Failed to register a ServiceWorker for scope ('http://localhost:3000/customers/') with script ('http://localhost:3000/customers/mockServiceWorker.js'): The script has an unsupported MIME type ('text/html').
I figured out that this is because it was looking for the service worker relative to the initial URL, so I need to change my start method to be absolute.
// old code
return setupWorker(...handlers).start();
// new code
return setupWorker(...handlers).start({
serviceWorker: {
url: '/mockServiceWorker.js',
},
});
Describe the solution you’d like
I was thinking to update the custom URL page in the docs to indicate that the default setting is to look for the service mocks at <HOSTNAME>/mockServiceWorker.js
but actually it looks for it at <initialURL>/mockServiceWorker.js
.
Perhaps I still don’t understand correctly but I believe that is the behavior.
Describe alternatives you’ve considered An alternative would be to update the default to
const DEFAULT_START_OPTIONS: DeepRequired<StartOptions> = {
serviceWorker: {
url: '/mockServiceWorker.js', // remove the initial "." on this url value
options: null as any,
},
quiet: false,
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top GitHub Comments
@mitchconquer, create a pull request from your fork to this repository, and let’s review it together. These instructions can be helpful to create a pull request from your fork. Looking forward to see your pull request 😃
Awesome thanks for the guidance! Here’s PR #153.