diff --git a/README.md b/README.md index 808eace88..1b330d9e5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index ba1d37850..81d6519f7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/request-api.js b/src/request-api.js index 3419536bf..d33597d9f 100644 --- a/src/request-api.js +++ b/src/request-api.js @@ -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 @@ -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) { diff --git a/test/api/ping.spec.js b/test/api/ping.spec.js index f2aa8e0e8..4763be0de 100644 --- a/test/api/ping.spec.js +++ b/test/api/ping.spec.js @@ -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