Skip to content

Commit

Permalink
CORS errors fixed in WebKit and Gecko based browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed Mar 25, 2019
1 parent 169fceb commit 9116b45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/web3-providers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions packages/web3-providers/src/factories/ProvidersModuleFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ export default class ProvidersModuleFactory {
* @returns {XMLHttpRequest}
*/
createXMLHttpRequest(host, timeout = 0, headers, agent, withCredentials) {
const request = new XHR();
request.nodejsSet(agent);
let request;

// runtime is of type node
if (typeof process !== 'undefined' && process.versions != null && process.versions.node != null) {
request = new XHR();
request.nodejsSet(agent);
} else {
request = new XMLHttpRequest();
}

request.open('POST', host, true);
request.setRequestHeader('Content-Type', 'application/json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('HttpProviderTest', () => {
{headers: [], timeout: 1, keepAlive: true, withCredentials: true},
providersModuleFactoryMock
);

expect(httpProvider.host).toEqual('http');

expect(httpProvider.headers).toEqual([]);
Expand Down

0 comments on commit 9116b45

Please sign in to comment.