当使用node.js应用程序中的以下代码以编程方式启动js节点时,它将启动群集,允许添加文件并将其查询回来。
// code from the docs: https://github.com/ipfs/js-ipfs#use-in-nodejs
const IPFS = require('ipfs')
const node = new IPFS()
node.on('ready', () => {
// Ready to use!
})
但是API和网关是不可用的,这意味着web无法检查回购内容。如何使用ipfs
npm包与ipfs一起启动API网关?
发布于 2019-05-21 18:15:24
找到答案,张贴在这里帮助任何人寻找类似的信息。
API网关可作为http
模块在ipfs
中使用,可以在ipfs节点开始时调用该模块,如下所示:
const IPFS = require('ipfs')
const node = new IPFS()
node.on('ready', () => {
// start the API gateway
const Gateway = require('ipfs/src/http');
const gateway = new Gateway(node);
return gateway.start();
})
API和网关将监听在new IPFS()
中使用的配置中指定的端口,这些端口可以从repo/config
文件位置编辑或编程提供,例如:
"Addresses": {
"API": "/ip4/127.0.0.1/tcp/5001",
"Gateway": "/ip4/127.0.0.1/tcp/8080"
}
发布于 2019-05-21 13:12:47
https://stackoverflow.com/questions/56213224
复制