From 6a21cd0b83dc85c3e954066f7ae1317aca0ff38a Mon Sep 17 00:00:00 2001 From: Friedel Ziegelmayer Date: Fri, 11 Nov 2016 22:35:39 +0100 Subject: [PATCH] feat(http): set default headers for browsers --- package.json | 11 ++++++++--- src/http-api/index.js | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6bbb23ad06..71cfe08d43 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,12 @@ "libp2p-ipfs": "libp2p-ipfs-browser", "./src/core/default-repo.js": "./src/core/default-repo-browser.js", "./src/core/components/init-assets.js": false, - "fs-pull-blob-store": false, - "glob": false, - "rimraf": false + "./test/utils/temp-repo.js": "./test/utils/temp-repo-browser.js", + "stream": "readable-stream" + }, + "engines": { + "node": ">=4.0.0", + "npm": ">=3.0.0" }, "scripts": { "lint": "aegir-lint", @@ -74,6 +77,7 @@ "fs-pull-blob-store": "^0.3.0", "glob": "^7.1.1", "hapi": "^15.2.0", + "hapi-set-header": "^1.0.2", "idb-pull-blob-store": "^0.5.1", "ipfs-api": "^11.1.0", "ipfs-bitswap": "^0.8.1", @@ -110,6 +114,7 @@ "pull-stream-to-stream": "^1.3.3", "pull-zip": "^2.0.1", "read-pkg-up": "^2.0.0", + "readable-stream": "^1.1.14", "stream-to-pull-stream": "^1.7.2", "tar-stream": "^1.5.2", "temp": "^0.8.3", diff --git a/src/http-api/index.js b/src/http-api/index.js index 0e46e0f33b..469f584ef2 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -8,6 +8,7 @@ const path = require('path') const IPFSRepo = require('ipfs-repo') const multiaddr = require('multiaddr') const Store = require('fs-pull-blob-store') +const setHeader = require('hapi-set-header') const log = debug('api') log.error = debug('api:error') @@ -52,6 +53,7 @@ exports = module.exports = function HttpApi (repo) { } } }) + this.server.app.ipfs = this.ipfs const api = config.Addresses.API.split('/') const gateway = config.Addresses.Gateway.split('/') @@ -75,6 +77,10 @@ exports = module.exports = function HttpApi (repo) { // load routes require('./routes')(this.server) + // Set default headers + setHeader(this.server, 'Access-Control-Allow-Headers', 'X-Stream-Output, X-Chunked-Output, X-Content-Length') + setHeader(this.server, 'Access-Control-Expose-Headers', 'X-Stream-Output, X-Chunked-Output, X-Content-Length') + this.ipfs.goOnline(() => { this.server.start((err) => { if (err) {