gpt4 book ai didi

ipfs - 如何在启动 js-ipfs 节点时启动 api 网关?

转载 作者:行者123 更新时间:2023-12-04 01:08:21 28 4
gpt4 key购买 nike

当在 node.js 应用程序中使用以下代码以编程方式启动 js-ipfs 节点时,它会启动 swarm,允许添加文件并查询它们。

// 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-ui 无法用于检查 repo 内容。如何使用 ipfs npm 包启动 API 网关和 ipfs swarm?

最佳答案

找到答案,张贴在这里以帮助任何寻找类似信息的人。

API 网关在 ipfs 中作为 http 模块提供,可以在 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"
}

关于ipfs - 如何在启动 js-ipfs 节点时启动 api 网关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56213224/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com