diff --git a/.gitignore b/.gitignore index 7cdb316de..db6288ec0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -node_modules -*.log +**/node_modules +**/*.log test/setup/tmp-disposable-nodes-addrs.json dist coverage diff --git a/README.md b/README.md index b5aafa336..ad71311cb 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ var ipfs = ipfsAPI({host: 'localhost', port: '5001', procotol: 'http'}) Same as in Node.js, you just have to [browserify](http://browserify.org) the code before serving it. See the browserify repo for how to do that. +See the example at the [examples folder](/examples/bundle-browserify) to get a boilerplate. + ### In a web browser from CDN Instead of a local installation (and browserification) you may request a remote copy of IPFS API from [unpkg CDN](https://unpkg.com/). diff --git a/examples/browser-add/README.md b/examples/browser-add/README.md deleted file mode 100644 index c052a5723..000000000 --- a/examples/browser-add/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# JS IPFS API - Example Browser - Add - -## Setup - -Install [go-ipfs](https://ipfs.io/docs/install/) and run it - -```bash -$ ipfs daemon -``` - -then in this folder run - -```bash -$ npm install -$ npm start -``` - -and open your browser at `http://localhost:8888` diff --git a/examples/browser-add/.gitignore b/examples/bundle-browserify/.gitignore similarity index 100% rename from examples/browser-add/.gitignore rename to examples/bundle-browserify/.gitignore diff --git a/examples/bundle-browserify/README.md b/examples/bundle-browserify/README.md new file mode 100644 index 000000000..80944615d --- /dev/null +++ b/examples/bundle-browserify/README.md @@ -0,0 +1,35 @@ +# Bundle js-ipfs-api with Browserify! + +> In this example, you will find a boilerplate you can use to guide yourself into bundling js-ipfs-api with browserify, 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\"]" +``` + +## Run this example + +Once the daemon is on, run the following commands within this folder: + +```bash +> npm install +> npm start +``` + +Now open your browser at `http://localhost:8888` + +You should see the following: + +![](https://ipfs.io/ipfs/QmNtpcWCEd6LjdPNfBFDaVZdD4jpgT8ZTAwoFJXKhYMJdo/1.png) +![](https://ipfs.io/ipfs/QmNtpcWCEd6LjdPNfBFDaVZdD4jpgT8ZTAwoFJXKhYMJdo/2.png) diff --git a/examples/bundle-browserify/img/1.png b/examples/bundle-browserify/img/1.png new file mode 100644 index 000000000..580511dad Binary files /dev/null and b/examples/bundle-browserify/img/1.png differ diff --git a/examples/bundle-browserify/img/2.png b/examples/bundle-browserify/img/2.png new file mode 100644 index 000000000..5c72fc0a3 Binary files /dev/null and b/examples/bundle-browserify/img/2.png differ diff --git a/examples/browser-add/index.html b/examples/bundle-browserify/index.html similarity index 83% rename from examples/browser-add/index.html rename to examples/bundle-browserify/index.html index bd165e2ff..77596e861 100644 --- a/examples/browser-add/index.html +++ b/examples/bundle-browserify/index.html @@ -13,10 +13,10 @@ -

JS IPFS API - Add file from the browser

+

JS IPFS API - Add data to IPFS from the browser

- +
found in ipfs:
[ipfs hash]
diff --git a/examples/browser-add/index.js b/examples/bundle-browserify/index.js similarity index 96% rename from examples/browser-add/index.js rename to examples/bundle-browserify/index.js index e3cad0d50..5216b7269 100644 --- a/examples/browser-add/index.js +++ b/examples/bundle-browserify/index.js @@ -1,6 +1,7 @@ 'use strict' -var IPFS = require('../../src') +var IPFS = require('ipfs-api') + var ipfs = IPFS() function store () { diff --git a/examples/browser-add/package.json b/examples/bundle-browserify/package.json similarity index 62% rename from examples/browser-add/package.json rename to examples/bundle-browserify/package.json index 6ac12312f..0d06ab502 100644 --- a/examples/browser-add/package.json +++ b/examples/bundle-browserify/package.json @@ -1,7 +1,7 @@ { - "name": "ipfs-api-example-browser-add", + "name": "bundle-browserify", "version": "1.0.0", - "description": "", + "description": "Bundle js-ipfs-api with Browserify", "main": "index.js", "scripts": { "start": "browserify index.js > bundle.js && http-server -a 127.0.0.1 -p 8888" @@ -10,7 +10,10 @@ "author": "Friedel Ziegelmayer", "license": "MIT", "devDependencies": { - "browserify": "^13.0.1", + "browserify": "^13.1.1", + "ipfs-api": "^11.1.0", "http-server": "^0.9.0" + }, + "dependencies": { } } diff --git a/examples/files-api.js b/examples/files-api/files-api.js similarity index 100% rename from examples/files-api.js rename to examples/files-api/files-api.js