Skip to content

Instantly share code, notes, and snippets.

@trashhalo trashhalo/ipfs.js
Created Oct 20, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.