Usinc Create React App, if I configure a "homepage" in my package.json the service-worker.js fails to load, because prefix is not added to service-worker.js path.
package.json:
"homepage": "/mypath"
app is loaded at:
http://localhost/mypath
service-worker.js is attempted to load from:
http://localhost/service-worker.js
service-worker.js should load load from:
http://localhost/mypath/service-worker.js
It would be a nice feature to be able to configure this. Thanks for a great package!
Hey, @Gonusi. Thanks for reaching out.
You can provide a custom Service Worker URL where MSW would try to find the worker script using the serviceWorker.url option of the worker:
const worker = setupWorker(...)
worker.start({
serviceWorker: {
url: '/mypath/mockServiceWorker.js'
}
})
Thank you, I managed to miss it by only looking for it in the "setupWorker" section.
Most helpful comment
Hey, @Gonusi. Thanks for reaching out.
You can provide a custom Service Worker URL where MSW would try to find the worker script using the
serviceWorker.urloption of theworker: