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

Commit

Permalink
fix: add some nice things/clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Dec 9, 2016
1 parent 4252559 commit a355c9e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 30 deletions.
20 changes: 2 additions & 18 deletions examples/bundle-webpack/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/cli/commands/files/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
8 changes: 5 additions & 3 deletions src/core/components/init-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
}),
Expand Down
4 changes: 3 additions & 1 deletion src/core/default-repo-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
7 changes: 5 additions & 2 deletions src/core/default-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
6 changes: 3 additions & 3 deletions src/init-files/default-config.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

6 comments on commit a355c9e

@dignifiedquire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid this is pretty confusing to change the defaults and not mention it in the commit message and not making it a PR!

@dignifiedquire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing those defaults means that all tools that use go-ipfs default ports fail with js-ipfs now. I was just trying my benchmark setup and it doesn't work anymore because the js-ipfs ports suddenly changed.

Most users will not want to run go-ipfs and js-ipfs side by side, but it's much more probably that they want to run either one with the same tools that expect the api on the same port. So I don't think it's good to change these defaults at all.

@daviddias
Copy link
Member Author

@daviddias daviddias commented on a355c9e Dec 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a huge pain to handle to change the IPFS repo every single time, it made demos look less smoth and make people that did jsipfs init confused why it is messing with their goipfs init.

I'll add a note of the default values of jsipfs to the README.

@dignifiedquire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that, but I am still not a fan of pushing breaking changes to master with no visible discussion or code review

@daviddias
Copy link
Member Author

@daviddias daviddias commented on a355c9e Dec 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, should have had a discussion through Github, my bad, won't open any exception again.

@dignifiedquire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you 🐳

Please sign in to comment.