Msw: Allow configuring "homepage"

Created on 21 Oct 2020  路  2Comments  路  Source: mswjs/msw

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!

question browser

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.url option of the worker:

const worker = setupWorker(...)

worker.start({
  serviceWorker: {
    url: '/mypath/mockServiceWorker.js'
  }
})

Read more in the docs

All 2 comments

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'
  }
})

Read more in the docs

Thank you, I managed to miss it by only looking for it in the "setupWorker" section.

Was this page helpful?
0 / 5 - 0 ratings