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

Fixed an error that ignored baseURL #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TonnyXu
Copy link

@TonnyXu TonnyXu commented Feb 7, 2024

Hey @Tibing

I found your library very useful, but has a small issue when axios is configured to use baseURL. Please take a look at this PR.

Best regards,
Tonny

@Tibing
Copy link
Contributor

Tibing commented Feb 12, 2024

Hi, thank you for the PR, I'll take a look as soon as I can

@TonnyXu
Copy link
Author

TonnyXu commented Feb 13, 2024

@Tibing We need to make a release with baseURL enabled ASAP, can you take a look at this PR?

@Tibing
Copy link
Contributor

Tibing commented May 29, 2024

Hi, sorry for the delayed response!

Could you please provide a bit more detail about the refactoring you're doing here?

  1. What's the purpose? What's the bug you're fixing? Steps to reproduce?
  2. Please, provide test cases so I can make sure everything works as expected

Comment on lines +54 to +66
const lowercasedUrl = config.url.toLowerCase();
const lowercasedBaseURL = config.baseURL?.toLowerCase();

let url:URL;
if (lowercasedUrl.startsWith('http:') || lowercasedUrl.startsWith('https:')) {
// config.url has a higher priority than config.baseURL
url = new URL(config.url);
} else if (config.baseURL && (lowercasedBaseURL.startsWith('http:') || lowercasedBaseURL.startsWith('https:'))) {
url = new URL(config.baseURL + config.url);
} else {
// failed to find a valid url
throw new Error('Invalid URL: ' + config.url + ' or baseURL: ' + config.baseURL);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should reside in a separate method or something like that

const lowercasedUrl = config.url.toLowerCase();
const lowercasedBaseURL = config.baseURL?.toLowerCase();

let url:URL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let url:URL;
let url: URL;

url = new URL(config.baseURL + config.url);
} else {
// failed to find a valid url
throw new Error('Invalid URL: ' + config.url + ' or baseURL: ' + config.baseURL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is not intended to throw an error, it should return false http2 not supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants