mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 18:19:40 +00:00
In domain-task, avoid use of "new Function" because of CSP. Fixes #345
This commit is contained in:
@@ -2,7 +2,7 @@ import * as url from 'url';
|
|||||||
import * as domain from 'domain';
|
import * as domain from 'domain';
|
||||||
import * as domainContext from 'domain-context';
|
import * as domainContext from 'domain-context';
|
||||||
const isomorphicFetch = require('isomorphic-fetch');
|
const isomorphicFetch = require('isomorphic-fetch');
|
||||||
const isBrowser: boolean = (new Function('try { return this === window; } catch (e) { return false; }'))();
|
const isNode = typeof process === 'object' && process.versions && !!process.versions.node;
|
||||||
|
|
||||||
// Not using a symbol, because this may need to run in a version of Node.js that doesn't support them
|
// Not using a symbol, because this may need to run in a version of Node.js that doesn't support them
|
||||||
const domainTaskStateKey = '__DOMAIN_TASK_INTERNAL_FETCH_BASEURL__DO_NOT_REFERENCE_THIS__';
|
const domainTaskStateKey = '__DOMAIN_TASK_INTERNAL_FETCH_BASEURL__DO_NOT_REFERENCE_THIS__';
|
||||||
@@ -17,7 +17,7 @@ function issueRequest(baseUrl: string, req: string | Request, init?: RequestInit
|
|||||||
} else {
|
} else {
|
||||||
req = url.resolve(baseUrl, req as string);
|
req = url.resolve(baseUrl, req as string);
|
||||||
}
|
}
|
||||||
} else if (!isBrowser) {
|
} else if (isNode) {
|
||||||
// TODO: Consider only throwing if it's a relative URL, since absolute ones would work fine
|
// TODO: Consider only throwing if it's a relative URL, since absolute ones would work fine
|
||||||
throw new Error(`
|
throw new Error(`
|
||||||
When running outside the browser (e.g., in Node.js), you must specify a base URL
|
When running outside the browser (e.g., in Node.js), you must specify a base URL
|
||||||
|
|||||||
Reference in New Issue
Block a user