Skip to content

baseUrl behavior does not correct #101

Open
@mnixry

Description

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()
};

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions