Skip to content

Instantly share code, notes, and snippets.

@trashhalo
Created October 20, 2017 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trashhalo/ebae4c8cca1f37b9ebf9e301653a0551 to your computer and use it in GitHub Desktop.
Save trashhalo/ebae4c8cca1f37b9ebf9e301653a0551 to your computer and use it in GitHub Desktop.
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