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

baseUrl behavior does not correct #101

Open
Tracked by #103
mnixry opened this issue Nov 12, 2021 · 2 comments
Open
Tracked by #103

baseUrl behavior does not correct #101

mnixry opened this issue Nov 12, 2021 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@mnixry
Copy link

mnixry commented Nov 12, 2021

Describe the bug
Since #97, axios-logger can log full request URL, which is nice for user.
However, it does not behave correct in some condition

To Reproduce
Steps to reproduce the behavior:

  1. Set up a baseUrl option in axios
  2. Apply axios-logger
  3. Send a request which has full URL which will override default axios baseUrl options
  4. We will get a wrong log.

For example, if we set baseUrl to https://example.com, and use axios instance to request https://another-example.com, axios will actually request https://another-example.com, but axios-logger will log https://example.com/https://another-example.com

Expected behavior
axios-logger should log https://another-example.com

Additional context
Possible related code:

combineURLs(baseURL: string, relativeURL?: string): string {
return relativeURL
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
: baseURL;
};

We can use URL object to correct its behavior

combineURLs(baseURL: string, relativeURL?: string): string {
    return new URL(relativeURL, baseURL).toString()
};
@hg-pyun
Copy link
Owner

hg-pyun commented Nov 18, 2021

@mnixry Oh, Thank you for report. It's a move that didn't get caught in the test case. I think this report will be of great help.

@hg-pyun hg-pyun added bug Something isn't working good first issue Good for newcomers labels Nov 18, 2021
@hg-pyun
Copy link
Owner

hg-pyun commented Nov 24, 2021

It will be release on 2.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants