-
-
Notifications
You must be signed in to change notification settings - Fork 240
fix: remove duplicate baseUrl in axios client #2624
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
base: main
Are you sure you want to change the base?
fix: remove duplicate baseUrl in axios client #2624
Conversation
…uplicate baseUrls
|
|
@ben-pietsch is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
@Ben-Pfirsich you'd want to run |
Hi @mrlubos, i cannot get the project to build locally. The × index > downloads and parses v2 without issues 10015ms |
Did you build the library? |
Yes, but when I try to the build in the root folder, I always get some different error. I am able to build some of the subfolders. |
@Ben-Pfirsich hard to say without knowing the error message. I'd start by building codegen-core, openapi-ts, potentially custom-client for tests. I think you also want to build |
@mrlubos I will try to build it again tomorrow. Did you see my answer to your comment on the code? |
Hi @mrlubos, I though of another option, that would maybe leave all the current config object alone. I do think this is more confusing from a user perspective though.
|
Explain why is it more confusing? Would there be any breaking change or weird behavior? Just looking at it quickly, I think it makes sense and could be applied across all clients |
Hi @mrlubos , i think there could be some edge cases, where is does not work. If someone has a (weird) url like this: /example/example/some-api/v1 where the baseURL is "/example", this logic would wrongly assume that the baseURL is already included in this URL: "/example/some-api/v1. I think it might be more robust to make sure that the Something like this (previously the baseURL from the axios instance was not included):
I think this is similar to what you suggested before. |
If this works I'm all for it! |
@mrlubos , I will try to implement this, but I just noticed that the |
What do you mean by "it will still try to append it to the baseUrl"? The implementation looks like this export const getUrl = ({
baseUrl,
path,
query,
querySerializer,
url: _url,
}: {
baseUrl?: string;
path?: Record<string, unknown>;
query?: Record<string, unknown>;
querySerializer: QuerySerializer;
url: string;
}) => {
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
let url = (baseUrl ?? '') + pathUrl;
if (path) {
url = defaultPathSerializer({ path, url });
}
let search = query ? querySerializer(query) : '';
if (search.startsWith('?')) {
search = search.substring(1);
}
if (search) {
url += `?${search}`;
}
return url;
}; It should return a valid absolute URL if possible. In your case, it won't do that, which is also fine. The problem stems from the internal Axios implementation that incorrectly duplicates the base. The point of this function is to construct the final URL we'll use in the request. It seems the easiest solution might be to simply exclude base URL from the Axios call since we construct it ourselves anyway |
@mrlubos, Am I overlooking something? |
@Ben-Pfirsich that's correct but how would you end up with domain in |
@mrlubos |
…getUrl while including axios defaults
Hi @mrlubos, I just pushed my second attempt. A few notes:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2624 +/- ##
=======================================
Coverage 23.83% 23.83%
=======================================
Files 379 379
Lines 36930 36951 +21
Branches 1626 1630 +4
=======================================
+ Hits 8803 8809 +6
- Misses 28114 28129 +15
Partials 13 13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
commit: |
Seems you figured it out. Do you know what was the problem? |
@mrlubos , |
@mrlubos, |
No description provided.