-
Notifications
You must be signed in to change notification settings - Fork 0
How to use with axios on Node? #15
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
Comments
As
axios on Node uses http and https https://github.com/axios/axios/blob/e9965bfafc82d8b42765705061b9ebe2d5532493/lib/defaults.js#L17-L27 As far as I can understand |
Tried dirty workaround with https://www.npmjs.com/package/xmlhttprequest
|
Had more luck with msw on Node.js out of the box:
|
Interesting find! After doing a quick deep-dive, there seems to be two factors at play here:
For (1), using the polyfills directly seems to work relatively well, as you've shown with For (2), Axios is supported for any environment that has This would be a relatively simple fix so I'll try to push one up soon. Thanks for bringing this up, it will help create a better product! |
@D-Pow, thanks for the answer! I made pull request driverdan/node-XMLHttpRequest#191 for node-XMLHttpRequest which solves my error. |
Nice! If it's any help, the main thing I noticed that caused this issue was more that the Specifically, consider a case like this: // Comments are console output.
/*** Native ***/
let xhr = new XMLHttpRequest();
// undefined
xhr.open('GET', '');
// undefined
xhr.getAllResponseHeaders()
// "" Here, So the key point I meant in my first reply is that they:
var headers = {};
var response = {
// values from the response object that are copied over to their middle-man response object.
// e.g.
headers: headers,
status: null, // or 1
// ... other keys with default values
};
// First, applies defaults from original `response` in (1).
// Second, overwrites `response` fields from (1) if they're present in the actual response, `resp`.
response = Object.assign({}, response, resp); If both (1) and (2) were addressed, there wouldn't be any other edge cases with other fields that you and I haven't figured out yet. |
# Enhance XMLHttpRequest docs and implementation This PR fixes issues [#14](#14), [#15](#15), and [#16](#16). Primary changes: * Add handlers for both `onload` and `onloadend` events in addition to `readystatechange` in order to support `axios@>=0.22.2`. * Support both `on[event]` and `addEventListener(event)` methods for `XMLHttpRequest`. * Add shim for usage in back-end/NodeJS scripts using `axios` with `XMLHttpRequest` polyfills. * Add extensive documentation in the ReadMe for how to use MockRequests in the back-end/NodeJS scripts. Secondary changes: * Update both MockRequests and its demo to use `node@>=14` for better dependency resolution. - Requires replacing `node-sass` with `sass` and fixing the incorrect re-defining of `vendor` in both `entry` and `optimization` within webpack.config.js. * Make homepage redirect to JSDoc website. * Ensure Jest DOM is defined by changing setup files from `setupFiles` to `setupFilesAfterEnv`. * Fix ReadMe links to work on npmjs.com (they already worked perfectly on GitHub, but npmjs.com is too primitive to understand renamed hyperlinks via `<a name="X"/>`). * Simplify wrapper overriding logic. * Add tests for all sorts of `addEventListener()` usages.
This should be fixed in PR #17. Please let me know if you still encounter any issues! |
The text was updated successfully, but these errors were encountered: