axios-logger icon indicating copy to clipboard operation
axios-logger copied to clipboard

baseUrl behavior does not correct

Open mnixry opened this issue 4 years ago • 2 comments

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: https://github.com/hg-pyun/axios-logger/blob/92125b5d2e3ed630a8cb1ac47334f84b056b09e4/src/common/string-builder.ts#L85-L89 We can use URL object to correct its behavior

combineURLs(baseURL: string, relativeURL?: string): string {
    return new URL(relativeURL, baseURL).toString()
};

mnixry avatar Nov 12 '21 11:11 mnixry

@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 avatar Nov 18 '21 14:11 hg-pyun

It will be release on 2.6.1

hg-pyun avatar Nov 24 '21 14:11 hg-pyun