index-fetch.js 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. 'use strict'
  2. const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')
  3. const EnvHttpProxyAgent = require('./lib/dispatcher/env-http-proxy-agent')
  4. const fetchImpl = require('./lib/web/fetch').fetch
  5. module.exports.fetch = function fetch (resource, init = undefined) {
  6. return fetchImpl(resource, init).catch((err) => {
  7. if (err && typeof err === 'object') {
  8. Error.captureStackTrace(err)
  9. }
  10. throw err
  11. })
  12. }
  13. module.exports.FormData = require('./lib/web/fetch/formdata').FormData
  14. module.exports.Headers = require('./lib/web/fetch/headers').Headers
  15. module.exports.Response = require('./lib/web/fetch/response').Response
  16. module.exports.Request = require('./lib/web/fetch/request').Request
  17. const { CloseEvent, ErrorEvent, MessageEvent, createFastMessageEvent } = require('./lib/web/websocket/events')
  18. module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket
  19. module.exports.CloseEvent = CloseEvent
  20. module.exports.ErrorEvent = ErrorEvent
  21. module.exports.MessageEvent = MessageEvent
  22. module.exports.createFastMessageEvent = createFastMessageEvent
  23. module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource
  24. // Expose the fetch implementation to be enabled in Node.js core via a flag
  25. module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent
  26. module.exports.getGlobalDispatcher = getGlobalDispatcher
  27. module.exports.setGlobalDispatcher = setGlobalDispatcher