Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion build/webpack.esModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/* eslint-env node */
import { merge } from 'webpack-merge';
import webpack from 'webpack';
import baseConfig from './webpack.common.js';
import { OUTPUT_PATH } from './utils.js';

Expand All @@ -21,6 +22,7 @@ const nodeConfig = {
resolve: {
alias: {},
fallback: {
buffer: 'buffer',
crypto: 'crypto-browserify',
stream: 'stream-browserify',
https: false,
Expand All @@ -29,7 +31,12 @@ const nodeConfig = {
fs: false,
url: false
}
}
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
]
};

export default merge(baseConfig, nodeConfig);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-sdk",
"version": "3.4.20",
"version": "3.4.21",
"description": "aelf-sdk js library",
"type": "module",
"main": "dist/aelf.cjs",
Expand Down
7 changes: 5 additions & 2 deletions src/util/httpProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author atom-yang
*/
import { stringify } from 'query-string';
import NodeFetch, { Headers } from 'node-fetch';
import NodeFetch, { Headers as NodeHeaders } from 'node-fetch';
import { XMLHttpRequest as XHR } from 'xmlhttprequest';

const defaultHeaders = {
Expand All @@ -14,12 +14,14 @@ const defaultHeaders = {
let RequestLibrary = {};
let RequestLibraryXMLOnly = null;
let isFetch = false;
let HeadersClass = null;
if (process.env.RUNTIME_ENV === 'browser') {
// For browsers use DOM Api XMLHttpRequest
// serviceworker without window and document, only with self
// eslint-disable-next-line no-restricted-globals
const _self = typeof self === 'object' ? self : {};
const _window = typeof window === 'object' ? window : _self;
HeadersClass = _window.Headers || null;
if (typeof _window.XMLHttpRequest !== 'undefined') {
RequestLibrary = _window.XMLHttpRequest;
isFetch = false;
Expand All @@ -31,6 +33,7 @@ if (process.env.RUNTIME_ENV === 'browser') {
// For node use xmlhttprequest
RequestLibraryXMLOnly = XHR;
RequestLibrary = NodeFetch;
HeadersClass = NodeHeaders;
isFetch = true;
}

Expand Down Expand Up @@ -104,7 +107,7 @@ export default class HttpProvider {
const { url, method = 'POST', params = {}, signal } = requestConfig;
const path = `/api/${url}`.replace(/\/\//g, '/');
let uri = `${this.host}${path}`.replace();
const myHeaders = new Headers();
const myHeaders = HeadersClass ? new HeadersClass() : {};
let body = JSON.stringify(params);
if (method.toUpperCase() === 'GET' || method.toUpperCase() === 'DELETE') {
uri = Object.keys(params).length > 0 ? `${uri}?${stringify(params)}` : uri;
Expand Down