1

Is there any way to configure msw to only intercept requests to paths with certain pattern?

For example only paths start with "/api".

Currently it shows warning every time I navigate to some page of my React app.

CSSer
  • 2,131
  • 2
  • 18
  • 37

1 Answers1

0

This should do it:

worker.start({
  onUnhandledRequest(req, print) {
    if (req.url.pathname.startsWith('/api/') {
      print.warning()
    }

    return;
  }
})

If you want to turn it off completely use:

worker.start({
  onUnhandledRequest: 'bypass',
})
Cathal Mac Donnacha
  • 1,285
  • 1
  • 16
  • 23