Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: differenciate default config in browser and in node (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias authored Jan 29, 2017
1 parent 8b1c55d commit 17ccc8b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
6 changes: 5 additions & 1 deletion src/core/components/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict'

const defaultNodes = require('../../init-files/default-config.json').Bootstrap
const isNode = require('detect-node')

const defaultNodes = isNode
? require('../../init-files/default-config-node.json').Bootstrap
: require('../../init-files/default-config-browser.json').Bootstrap

module.exports = function bootstrap (self) {
return {
Expand Down
15 changes: 5 additions & 10 deletions src/core/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const peerId = require('peer-id')
const waterfall = require('async/waterfall')
const parallel = require('async/parallel')
const isNode = require('detect-node')

const addDefaultAssets = require('./init-assets')

Expand All @@ -20,13 +21,9 @@ module.exports = function init (self) {
opts.bits = Number(opts.bits) || 2048
opts.log = opts.log || function () {}

let config
// Pre-set config values.
try {
config = require('../../init-files/default-config.json')
} catch (err) {
return callback(err)
}
const config = isNode
? require('../../init-files/default-config-node.json')
: require('../../init-files/default-config-browser.json')

waterfall([
// Verify repo does not yet exist.
Expand Down Expand Up @@ -62,9 +59,7 @@ module.exports = function init (self) {
]

if (typeof addDefaultAssets === 'function') {
tasks.push(
(cb) => addDefaultAssets(self, opts.log, cb)
)
tasks.push((cb) => addDefaultAssets(self, opts.log, cb))
}

parallel(tasks, (err) => {
Expand Down
9 changes: 9 additions & 0 deletions src/init-files/default-config-browser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Addresses": {
"Swarm": [],
"API": "/ip4/127.0.0.1/tcp/5002",
"Gateway": "/ip4/127.0.0.1/tcp/9090"
},
"Discovery": {},
"Bootstrap": []
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"Addresses": {
"Swarm": [
"/ip4/0.0.0.0/tcp/4002"
"/ip4/0.0.0.0/tcp/4002",
"/ip4/127.0.0.1/tcp/4003/ws"
],
"API": "/ip4/127.0.0.1/tcp/5002",
"Gateway": "/ip4/127.0.0.1/tcp/9090"
Expand All @@ -12,17 +13,6 @@
"Interval": 10
}
},
"Mounts": {
"IPFS": "/ipfs",
"IPNS": "/ipns"
},
"Ipns": {
"ResolveCacheSize": 128
},
"Gateway": {
"RootRedirect": "",
"Writable": false
},
"Bootstrap": [
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z",
Expand Down
2 changes: 1 addition & 1 deletion test/http-api/spec/test-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const expect = require('chai').expect
const qs = require('qs')
const defaultList = require('../../../src/init-files/default-config.json').Bootstrap
const defaultList = require('../../../src/init-files/default-config-node.json').Bootstrap

module.exports = (http) => {
describe('/bootstrap', () => {
Expand Down

0 comments on commit 17ccc8b

Please sign in to comment.