Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 4b4d864

Browse files
committed
docs: update example of browserify
1 parent c20bda5 commit 4b4d864

File tree

11 files changed

+49
-26
lines changed

11 files changed

+49
-26
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
node_modules
2-
*.log
1+
**/node_modules
2+
**/*.log
33
test/setup/tmp-disposable-nodes-addrs.json
44
dist
55
coverage

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ var ipfs = ipfsAPI({host: 'localhost', port: '5001', procotol: 'http'})
7979

8080
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.
8181

82+
See the example at the [examples folder](/examples/bundle-browserify) to get a boilerplate.
83+
8284
### In a web browser from CDN
8385

8486
Instead of a local installation (and browserification) you may request a remote copy of IPFS API from [unpkg CDN](https://unpkg.com/).

examples/browser-add/README.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

examples/bundle-browserify/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Bundle js-ipfs-api with Browserify!
2+
3+
> 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!
4+
5+
## Setup
6+
7+
As for any js-ipfs-api example, **you need a running IPFS daemon**, you learn how to do that here:
8+
9+
- [Spawn a go-ipfs daemon](https://ipfs.io/docs/getting-started/)
10+
- [Spawn a js-ipfs daemon](https://github.com/ipfs/js-ipfs#usage)
11+
12+
**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.
13+
14+
A quick (and dirty way to get it done) is:
15+
16+
```bash
17+
> ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"*\"]"
18+
> ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials "[\"true\"]"
19+
```
20+
21+
## Run this example
22+
23+
Once the daemon is on, run the following commands within this folder:
24+
25+
```bash
26+
> npm install
27+
> npm start
28+
```
29+
30+
Now open your browser at `http://localhost:8888`
31+
32+
You should see the following:
33+
34+
![](https://ipfs.io/ipfs/QmNtpcWCEd6LjdPNfBFDaVZdD4jpgT8ZTAwoFJXKhYMJdo/1.png)
35+
![](https://ipfs.io/ipfs/QmNtpcWCEd6LjdPNfBFDaVZdD4jpgT8ZTAwoFJXKhYMJdo/2.png)

examples/bundle-browserify/img/1.png

98.2 KB
Loading

examples/bundle-browserify/img/2.png

143 KB
Loading

examples/browser-add/index.html renamed to examples/bundle-browserify/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
</style>
1414
</head>
1515
<body>
16-
<h1>JS IPFS API - Add file from the browser</h1>
16+
<h1>JS IPFS API - Add data to IPFS from the browser</h1>
1717
<textarea id="source">
1818
</textarea>
19-
<button id="store">create in ipfs</button>
19+
<button id="store">add to ipfs</button>
2020
<div>
2121
<div>found in ipfs:</div>
2222
<div class="content" id="hash">[ipfs hash]</div>

examples/browser-add/index.js renamed to examples/bundle-browserify/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

3-
var IPFS = require('../../src')
3+
var IPFS = require('ipfs-api')
4+
45
var ipfs = IPFS()
56

67
function store () {
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "ipfs-api-example-browser-add",
2+
"name": "bundle-browserify",
33
"version": "1.0.0",
4-
"description": "",
4+
"description": "Bundle js-ipfs-api with Browserify",
55
"main": "index.js",
66
"scripts": {
77
"start": "browserify index.js > bundle.js && http-server -a 127.0.0.1 -p 8888"
@@ -10,7 +10,10 @@
1010
"author": "Friedel Ziegelmayer",
1111
"license": "MIT",
1212
"devDependencies": {
13-
"browserify": "^13.0.1",
13+
"browserify": "^13.1.1",
14+
"ipfs-api": "^11.1.0",
1415
"http-server": "^0.9.0"
16+
},
17+
"dependencies": {
1518
}
1619
}
File renamed without changes.

0 commit comments

Comments
 (0)