Skip to content

Commit

Permalink
fix(:bug:): support use in Node.js with custom fetch (and no global)
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-request

ISSUES CLOSED: #203
  • Loading branch information
jgravois committed Aug 1, 2018
1 parent 98f7b34 commit 90f9e75
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/arcgis-rest-request/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ export function request(
): Promise<any> {
const options: IRequestOptions = {
httpMethod: "POST",
fetch,
...requestOptions
};

const missingGlobals: string[] = [];
const recommendedPackages: string[] = [];

if (!options.fetch) {
// don't check for a global fetch if a custom implementation was passed through
if (!options.fetch && typeof fetch !== "undefined") {
options.fetch = fetch.bind(Function("return this")());
} else {
missingGlobals.push("`fetch`");
recommendedPackages.push("`isomorphic-fetch`");
}
Expand All @@ -158,10 +160,6 @@ export function request(
);
}

if (options.fetch === fetch) {
options.fetch = fetch.bind(Function("return this")());
}

const { httpMethod, authentication } = options;

const params: IParams = {
Expand Down

0 comments on commit 90f9e75

Please sign in to comment.