ipfsd-ctl
Version:
Spawn IPFS Daemons, JS or Go
40 lines (36 loc) • 920 B
JavaScript
import { isBrowser, isWebWorker } from 'wherearewe'
/**
* @param {object} args
* @param {import('./types').NodeType} args.type
*/
export default ({ type }) => {
/** @type {string[]} */
let swarm
// from the browser tell remote nodes to listen over WS
if (type !== 'proc' && (isBrowser || isWebWorker)) {
swarm = ['/ip4/127.0.0.1/tcp/0/ws']
// from the browser, in process nodes cannot listen on _any_ addrs
} else if (type === 'proc' && (isBrowser || isWebWorker)) {
swarm = []
} else {
swarm = ['/ip4/127.0.0.1/tcp/0']
}
return {
API: {
HTTPHeaders: {
'Access-Control-Allow-Origin': ['*'],
'Access-Control-Allow-Methods': [
'PUT',
'POST',
'GET'
]
}
},
Addresses: {
Swarm: swarm,
API: '/ip4/127.0.0.1/tcp/0',
Gateway: '/ip4/127.0.0.1/tcp/0',
RPC: '/ip4/127.0.0.1/tcp/0'
}
}
}