Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: use node-fetch in electron-renderer
Browse files Browse the repository at this point in the history
`fetch` needs to be polyfilled before importing ky-universal:
ky-universal won't use node-fetch because electron-renderer already has
global.fetch defined and we can't use the one from electron-renderer as
it returns different errors and makes HTTPS mocking impossible in tests

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed Aug 12, 2019
1 parent 77d7260 commit 6fa8f88
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/components/files-regular/add-from-url.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
'use strict'

const { URL } = require('iso-url')
const { default: ky } = require('ky-universal')
const nodeify = require('promise-nodeify')
const { isElectronRenderer } = require('ipfs-utils/src/env')
if (isElectronRenderer) {
// `fetch` needs to be polyfilled before importing ky-universal:
// ky-universal won't use node-fetch because electron-renderer already has global.fetch defined
// and we can't use the one from electron-renderer as it returns different
// errors and makes HTTPS mocking impossible in tests
// TODO: remove when upstream fix lands
global.fetch = require('node-fetch')
}
const { default: ky } = require('ky-universal')

module.exports = (ipfs) => {
const addFromURL = async (url, opts = {}) => {
Expand Down

0 comments on commit 6fa8f88

Please sign in to comment.