Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger prints an absolute URL for a relative request URL #164

Closed
kettanaito opened this issue May 18, 2020 · 1 comment · Fixed by #167
Closed

Logger prints an absolute URL for a relative request URL #164

kettanaito opened this issue May 18, 2020 · 1 comment · Fixed by #167
Labels
bug Something isn't working scope:browser Related to MSW running in a browser

Comments

@kettanaito
Copy link
Member

Describe the bug

When performed a request relative to the current origin, the logger outputs an absolute URL in the browser's console.

Environment

  • msw: 0.16.0

Chrome Version 81.0.4044.138 (Official Build) (64-bit)

To Reproduce

Steps to reproduce the behavior:

  1. Setup an interception for POST /login
  2. Perform the POST /login request.
  3. See the absolute URL in the browser's log.

Expected behavior

Requests performed relatively to the current origin are displayed without the origin in the browser logs:

[MSW] 00:00:00 POST /login (200)

Screenshots

If applicable, add screenshots to help explain your problem.

Screen Shot 2020-05-18 at 11 07 59

@kettanaito kettanaito added bug Something isn't working scope:browser Related to MSW running in a browser labels May 18, 2020
@kettanaito
Copy link
Member Author

The req.referrer contains a trailing slash (/), while req.url.origin does not. The logic that determines whether a request URL is relative should swap places those two:

const isLocal = req.referrer.startsWith(req.url.origin)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scope:browser Related to MSW running in a browser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant