Closed CodingDick closed 2 years ago
The fakeXMLHttpRequest
is needed since Node.js does not provide this function.
This library works on Node.js where fakeXMLHttpRequest
does not exist so it would not even be possible to make a http request using fakeXMLHttpRequest
. To make http requests on Node.js, I recommend you using node-fetch.
I am using the Morlalis SDK-Package for node-js. And overwriting this globally prevends other packages to use axios for example: https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/7ac097aa79e6faefcae4b15b62b5005e0a98430e/src/MoralisWeb3Api.js#L127
Oh yes. Axios is isomorphic and therefore uses XMLHttpRequest
.
@yandeu, sorry but i do not get what you want to tell me (:
I just added a description. Please try it: https://github.com/geckosio/phaser-on-nodejs#using-node-fetch-or-axios
Thanks for that edit, but it does not help me. The package i am using, uses axios. And i can not modify this package and control the initialization of axios.
Moralis uses axios under the hood:
let tokenInfo = await Moralis.Web3API.account.getNFTsForContract({ chain: 'matic', token_address: TOKEN_ADRESS, address: user.ethAddress })
Try the hack around tokenInfo
or when you call something from Moralis.
Unfortunately there is no other workaround. Unfortunately, axios' "isBrowserCheck" is not very reliable. Maybe you could make a PR for axios.
Or remove axios from Moralis.
Sorry for replying that late. But i got a great solution for that. I got rid of Moralis and used web3.js directly instead to gather information from the polygon blockchain. For anyone having the same issue, try using web3.js
Your mentionted trick works because web3.js does this under the hood: ` HttpProvider.prototype._prepareRequest = function () {
var request;
// the current runtime is a browser
if (typeof XMLHttpRequest !== 'undefined') {
request = new XMLHttpRequest();
}
`
Describe the bug I would like to send a http-request, but all request get handled by the FakeXMLHttpRequest class. The reason is, that this particular class overwrites HTTP-Request globally. https://github.com/geckosio/phaser-on-nodejs/blob/master/src/index.ts#L21
My only chance to send an normal request is to comment those line out, because i can not see a config for that.
Have a question? Why do you need that "faker" and could it be possible to configure it?