Msw: Forward leading slash to match the page's hostname

Created on 4 Mar 2020  路  3Comments  路  Source: mswjs/msw

Current behavior expects the developer to either specify an entire hostname (http://backend.com/users) or use a wildcard (*/users) to handle request URI.

Motivation

It's familiar to developers to specify routes with a leading slash and expecting the hostname to be matched implicitly.

Expected behavior

When provided the route /users MSW would match any /users requests that are fired from the _current page's hostname_:

  • http://localhost:8080/users

However, it won't match the same paths from the different hostname:

  • https://api.dev.backend/users

All 3 comments

Perfect. Thank you!

@kentcdodds thank you for illustrating how confusing this gets in your stream. This should be a trivial change.

Released in 0.5.1. Examples in the documentation were updated to use the leading slash without a wildcard, where applicable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielstreit picture danielstreit  路  3Comments

baker-travis picture baker-travis  路  3Comments

abrudin picture abrudin  路  3Comments

balavishnuvj picture balavishnuvj  路  4Comments

tomalexhughes picture tomalexhughes  路  3Comments