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

Commit

Permalink
Merge pull request #25 from ethereum/ipfsnode
Browse files Browse the repository at this point in the history
add ipfs node
  • Loading branch information
yann300 authored Jan 20, 2021
2 parents 6ffe998 + 970ee0d commit 2e345de
Show file tree
Hide file tree
Showing 3 changed files with 7,218 additions and 1,594 deletions.
48 changes: 47 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const remixd = require('remixd')
const path = require('path')
const os = require('os')
const IPFS = require('ipfs')
const IPFSGateway = require('ipfs-http-gateway')

const { version } = require('./package.json')
const applicationMenu = require('./applicationMenu')
Expand Down Expand Up @@ -33,11 +35,34 @@ function createWindow () {
shell.openExternal(url);
})
win.loadURL('package://github.com/ethereum/remix-project')

// Modify the user agent for all requests to the following urls.
const filter = {
urls: ['https://*.dyn.plugin.remixproject.org/ipfs/*']
}
let hashes = {}
win.webContents.session.webRequest.onBeforeRequest(filter, (details, callback) => {
let { url } = details;
let reg = /dyn.plugin.remixproject.org\/ipfs\/(.*)/
let regResult = reg.exec(url)
const hash = regResult[1]
hashes[hash] = url
url = `http://localhost:5001/ipfs/${regResult[1]}`
callback({
cancel: false,
url: ( encodeURI(url ) )
})
})

win.webContents.session.webRequest.onErrorOccurred((details) => {
console.error(details)
})
}

app.on('ready', () => {
remixdStart()
createWindow()
createWindow()
ipfsStart()
})

let remixdStart = () => {
Expand All @@ -54,3 +79,24 @@ let remixdStart = () => {
throw new Error(error)
}
}

let ipfsStart = async () => {
try {
const repo = os.homedir() + '/.remix-ipfsnode'
const node = await IPFS.create({
repo,
config: {
Addresses: {
Gateway: `/ip4/127.0.0.1/tcp/5001`
}
}
})
const gateway = new IPFSGateway(node)
const id = await node.id()
gateway.start()
console.log('ipfs node', id)
console.log('ipfs node repo', repo)
} catch (err) {
console.error(err)
}
}
Loading

0 comments on commit 2e345de

Please sign in to comment.