From 6d52e1c34496de7adb7df57eba9b62637cd580f8 Mon Sep 17 00:00:00 2001 From: David Dias Date: Fri, 9 Dec 2016 14:27:10 -0800 Subject: [PATCH] fix: change default values of js-ipfs to avoid clash with go-ipfs + clean the browserify example --- examples/bundle-webpack/README.md | 20 ++------------------ src/cli/commands/daemon.js | 2 +- src/cli/commands/files/cat.js | 5 ++++- src/cli/utils.js | 2 +- src/core/components/init-assets.js | 8 +++++--- src/core/default-repo-browser.js | 4 +++- src/core/default-repo.js | 7 +++++-- src/init-files/default-config.json | 6 +++--- 8 files changed, 24 insertions(+), 30 deletions(-) diff --git a/examples/bundle-webpack/README.md b/examples/bundle-webpack/README.md index 6349cab743..173176ebbe 100644 --- a/examples/bundle-webpack/README.md +++ b/examples/bundle-webpack/README.md @@ -1,22 +1,6 @@ -# Bundle js-ipfs-api with Webpack! +# Bundle js-ipfswith Webpack! -> In this example, you will find a boilerplate you can use to guide yourself into bundling js-ipfs-api with webpack, so that you can use it in your own web app! - -## Setup - -As for any js-ipfs-api example, **you need a running IPFS daemon**, you learn how to do that here: - -- [Spawn a go-ipfs daemon](https://ipfs.io/docs/getting-started/) -- [Spawn a js-ipfs daemon](https://github.com/ipfs/js-ipfs#usage) - -**Note:** If you load your app from a different domain than the one the daemon is running (most probably), you will need to set up CORS, see https://github.com/ipfs/js-ipfs-api#cors to learn how to do that. - -A quick (and dirty way to get it done) is: - -```bash -> ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"*\"]" -> ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials "[\"true\"]" -``` +> In this example, you will find a boilerplate you can use to guide yourself into bundling js-ipfs with webpack, so that you can use it in your own web app! ## Run this example diff --git a/src/cli/commands/daemon.js b/src/cli/commands/daemon.js index 11fdba83ee..fb7d8c2614 100644 --- a/src/cli/commands/daemon.js +++ b/src/cli/commands/daemon.js @@ -16,7 +16,7 @@ module.exports = { console.log('Initializing daemon...') httpAPI = new HttpAPI(process.env.IPFS_PATH) httpAPI.start((err) => { - if (err.code === 'ENOENT') { + if (err && err.code === 'ENOENT') { console.log('Error: no ipfs repo found in ' + process.env.IPFS_PATH) console.log('please run: jsipfs init') process.exit(1) diff --git a/src/cli/commands/files/cat.js b/src/cli/commands/files/cat.js index 2b804d4e34..0fe9e9ed91 100644 --- a/src/cli/commands/files/cat.js +++ b/src/cli/commands/files/cat.js @@ -14,7 +14,10 @@ module.exports = { builder: {}, handler (argv) { - const path = argv['ipfs-path'] + let path = argv['ipfs-path'] + if (path.indexOf('/ipfs/') !== 1) { + path = path.replace('/ipfs/', '') + } waterfall([ (cb) => utils.getIPFS(cb), diff --git a/src/cli/utils.js b/src/cli/utils.js index d4d51a06e7..be2695f815 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -47,7 +47,7 @@ exports.getIPFS = (callback) => { } exports.getRepoPath = () => { - return process.env.IPFS_PATH || os.homedir() + '/.ipfs' + return process.env.IPFS_PATH || os.homedir() + '/.jsipfs' } exports.createLogger = (visible) => { diff --git a/src/core/components/init-assets.js b/src/core/components/init-assets.js index 6cc60fd61e..dd71341b3a 100644 --- a/src/core/components/init-assets.js +++ b/src/core/components/init-assets.js @@ -6,7 +6,7 @@ const glob = require('glob') const importer = require('ipfs-unixfs-engine').importer const pull = require('pull-stream') const file = require('pull-file') -const mh = require('multihashes') +// const mh = require('multihashes') // Add the default assets to the repo. module.exports = function addDefaultAssets (self, log, callback) { @@ -35,10 +35,12 @@ module.exports = function addDefaultAssets (self, log, callback) { importer(self._ipldResolver), pull.through((el) => { if (el.path === 'files/init-docs/docs') { - const hash = mh.toB58String(el.multihash) + // const hash = mh.toB58String(el.multihash) log('to get started, enter:') log() - log(`\t jsipfs files cat /ipfs/${hash}/readme`) + log(`\t jsipfs files cat /ipfs/QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB`) + // TODO when we support pathing in unixfs-engine + // log(`\t jsipfs files cat /ipfs/${hash}/readme`) log() } }), diff --git a/src/core/default-repo-browser.js b/src/core/default-repo-browser.js index 00741dbe0d..604127350e 100644 --- a/src/core/default-repo-browser.js +++ b/src/core/default-repo-browser.js @@ -5,5 +5,7 @@ const IPFSRepo = require('ipfs-repo') module.exports = (dir) => { const repoPath = dir || 'ipfs' - return new IPFSRepo(repoPath, {stores: Store}) + return new IPFSRepo(repoPath, { + stores: Store + }) } diff --git a/src/core/default-repo.js b/src/core/default-repo.js index 95afd9b92c..c826416668 100644 --- a/src/core/default-repo.js +++ b/src/core/default-repo.js @@ -6,6 +6,9 @@ const IPFSRepo = require('ipfs-repo') const path = require('path') module.exports = (dir) => { - const repoPath = dir || path.join(os.homedir(), '.ipfs') - return new IPFSRepo(repoPath, {stores: Store}) + const repoPath = dir || path.join(os.homedir(), '.jsipfs') + + return new IPFSRepo(repoPath, { + stores: Store + }) } diff --git a/src/init-files/default-config.json b/src/init-files/default-config.json index 7f74d4f3df..33046e3871 100644 --- a/src/init-files/default-config.json +++ b/src/init-files/default-config.json @@ -1,10 +1,10 @@ { "Addresses": { "Swarm": [ - "/ip4/0.0.0.0/tcp/4001" + "/ip4/0.0.0.0/tcp/4002" ], - "API": "/ip4/127.0.0.1/tcp/5001", - "Gateway": "/ip4/127.0.0.1/tcp/8080" + "API": "/ip4/127.0.0.1/tcp/5002", + "Gateway": "/ip4/127.0.0.1/tcp/9090" }, "Discovery": { "MDNS": {