node-ponyfill.js 624 B

12345678910111213141516171819202122
  1. const nodeFetch = require('node-fetch')
  2. const realFetch = nodeFetch.default || nodeFetch
  3. const fetch = function (url, options) {
  4. // Support schemaless URIs on the server for parity with the browser.
  5. // Ex: //github.com/ -> https://github.com/
  6. if (/^\/\//.test(url)) {
  7. url = 'https:' + url
  8. }
  9. return realFetch.call(this, url, options)
  10. }
  11. fetch.ponyfill = true
  12. module.exports = exports = fetch
  13. exports.fetch = fetch
  14. exports.Headers = nodeFetch.Headers
  15. exports.Request = nodeFetch.Request
  16. exports.Response = nodeFetch.Response
  17. // Needed for TypeScript consumers without esModuleInterop.
  18. exports.default = fetch