Fixing defaults to use httpAdapter if available (#1285)#9
Open
MitchLewis930 wants to merge 1 commit intopr_029_beforefrom
Open
Fixing defaults to use httpAdapter if available (#1285)#9MitchLewis930 wants to merge 1 commit intopr_029_beforefrom
MitchLewis930 wants to merge 1 commit intopr_029_beforefrom
Conversation
* Fixing defaults to use httpAdapter if available * Use a safer, cross-platform method to detect the Node environment
Greptile OverviewGreptile SummaryImproved environment detection in Key changes:
The more robust check ensures that the HTTP adapter is used in actual Node.js environments, while the XHR adapter is correctly selected in browsers even when webpack polyfills create a Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant App as Application Code
participant Defaults as lib/defaults.js
participant HttpAdapter as lib/adapters/http.js
participant XhrAdapter as lib/adapters/xhr.js
App->>Defaults: Import and initialize defaults
Defaults->>Defaults: Call getDefaultAdapter()
alt Running in Node.js
Defaults->>Defaults: Check typeof process !== 'undefined'
Defaults->>Defaults: Check Object.prototype.toString.call(process) === '[object process]'
Defaults->>HttpAdapter: require('./adapters/http')
HttpAdapter-->>Defaults: Return HTTP adapter function
Defaults-->>App: Use HTTP adapter (Node.js)
else Running in Browser
Defaults->>Defaults: Check typeof process !== 'undefined' (may exist due to webpack)
Defaults->>Defaults: Check Object.prototype.toString.call(process) === '[object process]' (fails for webpack polyfill)
Defaults->>Defaults: Check typeof XMLHttpRequest !== 'undefined'
Defaults->>XhrAdapter: require('./adapters/xhr')
XhrAdapter-->>Defaults: Return XHR adapter function
Defaults-->>App: Use XHR adapter (Browser)
end
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR_029