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

Fix moxios by not forcing adapters to resolve baseURL #2751

Closed
wants to merge 8 commits into from
Closed

Fix moxios by not forcing adapters to resolve baseURL #2751

wants to merge 8 commits into from

Conversation

brandon-leapyear
Copy link

@brandon-leapyear brandon-leapyear commented Feb 16, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


Fixes #2650

Adapters should not have to care about baseURL; everything should be fully resolved by the point it gets to the adapter. The original PR (#2391) broke moxios tests that used baseURL in the production code, but stubbed requests using full URLs.

This PR should maintain the behavior the first PR set out to fix (namely, that the config URL is not modified) while allowing adapters to have the same behavior as before the first PR. In general, I recommend not modifying the config at all in dispatchRequest, but this fix should suffice for the issue above

@brandon-leapyear brandon-leapyear changed the title Fix moxios Fix moxios by not forcing adapters to resolve baseURL Feb 16, 2020
@chinesedfan
Copy link
Collaborator

chinesedfan commented Feb 16, 2020

The changes of config is one of the most annoying things in axios. It happens in several files, and no clear documents record them. I think we should reach a consensus first, and write lots of tests to cover as more cases as possible.

In adapters, I agree that they should not care about things like combining baseURL with url. But will some users want to get the original config.url by response.config.url?

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Feb 16, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


But will some users want to get the original config.url

I say wait until we see a use case. If one comes up, we could always add a rawUrl field, but I don't think we need to be proactive with this until we see a need for it

@floriangosse
Copy link

Any decision made for that? Can I help somehow?

@chinesedfan
Copy link
Collaborator

chinesedfan commented Feb 26, 2020

This PR should maintain the behavior the first PR set out to fix

@brandon-leapyear Can you add a test case for #1628? I don't think you kept that. Because error.config received in response interceptor is the config in adapters, which is modified.

@floriangosse You can help test or give any opinions you have. We are glad to hear more suggestions.

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Feb 26, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


The PR fixing #1628 added a test that I didn't change

https://github.com/multicolaure/axios/blob/4f546cc415f72b5c5efc664939db82d6daf0d3bf/test/specs/requests.spec.js#L248

@chinesedfan
Copy link
Collaborator

@brandon-leapyear That's why CI is failed now.

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Mar 2, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


@chinesedfan ah got it. How does that fix look?

@chinesedfan
Copy link
Collaborator

chinesedfan commented Mar 4, 2020

I say wait until we see a use case. If one comes up, we could always add a rawUrl field, but I don't think we need to be proactive with this until we see a need for it

@brandon-leapyear I realized that #1628 was the case. Now the test passed but was not satisfied with #1628. Adding rawUrl is one of possible solutions. And hope you or someone can find out an ideal solution without extra field.

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Mar 4, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


@chinesedfan the more I think about this, the more I think avoiding config modification is the correct solution. Then, the error that interceptors receive could have both the rawConfig that was first passed into axios, and the config that was actually resolved.

It solves #1628 in the sense that the original goal was to rerun the request, using the same config initially passed into the request. This goes beyond the baseURL/url issue; even after "solving" #1628 with the initial solution, config modifications would happen twice, e.g. config.data = transformData(...). It just so happens that the baseURL/url issue is the most visible way that this is broken

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Mar 4, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


Blocked by #2798

@yujihu
Copy link

yujihu commented Apr 23, 2020

I think it should be consistent because many adapters rely on config.url. If the config.url changes, it's destructive to them.

@Oripi
Copy link

Oripi commented May 6, 2020

any updates on this?

@mzabriskie
Copy link
Member

A recent code change to moxios now takes into account config.baseURL. This will ought to be considered if this change is made. See axios/moxios#25

@chinesedfan
Copy link
Collaborator

Holy shit! It's @mzabriskie. Will you come back to lead axios or give me 30mins to discuss its future? You can find me on GitHub/Gitter and slacks.

@brandon-leapyear
Copy link
Author

brandon-leapyear commented Jun 30, 2020

This is an old work account. Please reference @brandonchinn178 for all future communication


ah thanks @mzabriskie. This PR can be closed, in that case, although I highly recommend #2798 anyway, to avoid modifying configs as it gets passed around

@jasonsaayman
Copy link
Member

Closing

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.

Moxios not working in 0.19.1
7 participants