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

0.3.10 #169

Merged
merged 6 commits into from
Dec 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ When using the api from script tag for things that require buffers (`ipfs.add`,

## CORS

If are using this module in a browser with something like browserify, then you will get an error saying that the origin is not allowed. This would be a CORS ("Cross Origin Resource Sharing") failure. The ipfs server rejects requests from unknown domains by default. You can whitelist the domain that you are calling from by exporting `API_ORIGIN` and restarting the daemon, like:
If are using this module in a browser with something like browserify, then you will get an error saying that the origin is not allowed. This would be a CORS ("Cross Origin Resource Sharing") failure. The ipfs server rejects requests from unknown domains by default. You can whitelist the domain that you are calling from by changing your ipfs config like this:

```bash
export API_ORIGIN="http://localhost:8080"
ipfs daemon
$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\"http://example.com\"]"
```

## API
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"concurrently": "^1.0.0",
"eslint-config-standard": "^4.4.0",
"eslint-plugin-standard": "^1.3.1",
"glob-stream": "5.2.0",
"gulp": "^3.9.0",
"gulp-bump": "^1.0.0",
"gulp-eslint": "^1.0.0",
Expand All @@ -44,7 +45,7 @@
"gulp-tag-version": "^1.3.0",
"gulp-util": "^3.0.7",
"https-browserify": "0.0.1",
"ipfsd-ctl": "^0.6.1",
"ipfsd-ctl": "^0.7.1",
"json-loader": "^0.5.3",
"karma": "^0.13.11",
"karma-chrome-launcher": "^0.2.1",
Expand Down
13 changes: 5 additions & 8 deletions src/request-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Wreck = require('wreck')
const Qs = require('qs')
const ndjson = require('ndjson')
const getFilesStream = require('./get-files-stream')

const isNode = !global.window
Expand All @@ -10,14 +11,10 @@ const isNode = !global.window

function parseChunkedJson (res, cb) {
const parsed = []
res.on('data', chunk => {
try {
parsed.push(JSON.parse(chunk))
} catch (err) {
// Browser quirks emit more than needed sometimes
}
})
res.on('end', () => cb(null, parsed))
res
.pipe(ndjson.parse())
.on('data', parsed.push.bind(parsed))
.on('end', () => cb(null, parsed))
}

function onRes (buffer, cb) {
Expand Down
5 changes: 0 additions & 5 deletions test/api/ping.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

describe('.ping', () => {
it('ping another peer', done => {
// TODO remove this when https://github.com/ipfs/js-ipfs-api/issues/135 is resolved
if (!isNode) {
return done()
}

apiClients['b'].id((err, id) => {
expect(err).to.not.exist

Expand Down