Created
October 20, 2017 02:36
-
-
Save trashhalo/ebae4c8cca1f37b9ebf9e301653a0551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import IPFS from 'ipfs'; | |
import Promise from 'bluebird'; | |
let ipfs; | |
const settings = { | |
repo: String(Math.random() + Date.now()), | |
IpfsDataDir: '/ipfs', | |
Addresses: { | |
API: '/ip4/127.0.0.1/tcp/0', | |
Swarm: [ | |
'/ip4/0.0.0.0/tcp/0' | |
], | |
Gateway: '/ip4/0.0.0.0/tcp/0' | |
}, | |
SignalServer: 'star-signal.cloud.ipfs.team', | |
API: { | |
HTTPHeaders: { | |
'Access-Control-Allow-Origin': ['*'], | |
'Access-Control-Allow-Methods': ['PUT', 'GET', 'POST'], | |
'Access-Control-Allow-Credentials': ['true'] | |
} | |
}, | |
EXPERIMENTAL: { | |
pubsub: true | |
}, | |
Discovery: { | |
MDNS: { | |
Enabled: false, | |
Interval: 10 | |
}, | |
webRTCStar: { | |
Enabled: true | |
} | |
} | |
}; | |
export default () => { | |
if (ipfs) { | |
return Promise.resolve(ipfs); | |
} | |
return new Promise((resolve, reject) => { | |
ipfs = new IPFS(settings); | |
ipfs.on('ready', () => { | |
resolve(ipfs); | |
}); | |
ipfs.on('error', (err) => { | |
reject(err); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment