我使用openwhisk-devtools设置了一个在docker上运行的openwhisk的本地实例。我已经创建了一个操作,该操作试图在我的机器上运行端口为8081的API。代码是这样的:
import axios from 'axios';
async function main () {
let response = null;
try {
response = await axios.get('http://localhost:8081/api/health-check');
} catch (error) {
return {
payload: {
error: error
}
}
}
return {
payload: {
headers: response.headers
}
};
}
global.main = main;我得到的错误是:
{
"code": "ECONNREFUSED",
"config": {
"headers": {
"Accept": "application/json, text/plain, */*",
"User-Agent": "axios/0.20.0"
},
"maxBodyLength": -1,
"maxContentLength": -1,
"method": "get",
"timeout": 0,
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http://localhost:8081/api/health-check",
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN"
},
"message": "connect ECONNREFUSED 127.0.0.1:8081",
"name": "Error",
"stack": "Error: connect ECONNREFUSED 127.0.0.1:8081\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)"
}我认为这是因为localhost指向正在运行该操作的docker容器。我怎样才能让这个请求转到我的开发机器上?
发布于 2020-10-03 05:05:17
在打印process.env的值之后,我发现了一个属性:
"__OW_API_HOST": "https://192.168.2.61",一开始我不太确定它是什么,但我在这里尝试了一个请求,它起作用了:
axios.get('http://192.169.2.61:8081/api/health-check')因此,process.env.__OW_API_HOST可能包含指向您的本地计算机的ip,您可以使用它。
https://stackoverflow.com/questions/64177744
复制相似问题