logic.js 中的函数在 playground 中有效,但在 REST 服务器中无效
Function in logic.js works in playground but not in REST server
我的 logic.js 文件中有一个函数可以从 api 检索飞机的纬度和经度:
function getLocation(){
var url = 'https://opensky-network.org/api/states/all?time=1458564121&icao24=3c6444'
return fetch(url) // Call the fetch function passing the url of the API as a parameter
.then(function(resp){
data = resp.json() // Transform the data into json
return data
}).then(function(data) {
lat = data.states[0][5]
long = data.states[0][6]
lat = lat.toString()
long = long.toString()
location = [lat,long]
return location
})
}
}
当我在操场上测试这个功能时,它成功地检索了飞机的纬度和经度。但是,当我尝试通过作曲家 REST 服务器执行相同的功能时,出现以下错误:
Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: chaincode error (status: 500, message: ReferenceError: identifier 'fetch' undefined)
有谁知道为什么会这样吗?
认为 fetch()
是一个 Web 浏览器(库)API,尤其是在 Playground 中使用带有 'fake' 结构的 Web 连接时 - 而它在 Composer REST 服务器中不可用/ 运行时看起来像(当调用函数的相关事务被调用时)。
Hyperledger Composer 允许您 call-outs - 在此处查看更多内容 https://hyperledger.github.io/composer/integrating/call-out
可以从那里调用 OpenSky REST APIs(如果可能,结果作为 JS 对象返回)
例如。获取 /states/all 示例
var url = "https://opensky-network.org/api/states/all?time=1458564121&icao24=3c6444";
return post( url, postTransaction)
.then(function (resp) {
// same code as you had before
});
响应(resp)的正文属性如果可能会自动转换为JS对象,否则以字符串形式返回。
我的 logic.js 文件中有一个函数可以从 api 检索飞机的纬度和经度:
function getLocation(){
var url = 'https://opensky-network.org/api/states/all?time=1458564121&icao24=3c6444'
return fetch(url) // Call the fetch function passing the url of the API as a parameter
.then(function(resp){
data = resp.json() // Transform the data into json
return data
}).then(function(data) {
lat = data.states[0][5]
long = data.states[0][6]
lat = lat.toString()
long = long.toString()
location = [lat,long]
return location
})
}
}
当我在操场上测试这个功能时,它成功地检索了飞机的纬度和经度。但是,当我尝试通过作曲家 REST 服务器执行相同的功能时,出现以下错误:
Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: chaincode error (status: 500, message: ReferenceError: identifier 'fetch' undefined)
有谁知道为什么会这样吗?
认为 fetch()
是一个 Web 浏览器(库)API,尤其是在 Playground 中使用带有 'fake' 结构的 Web 连接时 - 而它在 Composer REST 服务器中不可用/ 运行时看起来像(当调用函数的相关事务被调用时)。
Hyperledger Composer 允许您 call-outs - 在此处查看更多内容 https://hyperledger.github.io/composer/integrating/call-out
可以从那里调用 OpenSky REST APIs(如果可能,结果作为 JS 对象返回)
例如。获取 /states/all 示例
var url = "https://opensky-network.org/api/states/all?time=1458564121&icao24=3c6444";
return post( url, postTransaction)
.then(function (resp) {
// same code as you had before
});
响应(resp)的正文属性如果可能会自动转换为JS对象,否则以字符串形式返回。