+-
我在一个调用另一个的微服务中有以下代码:
axios.get('http://localhost:4210/usermicroservice/heartbeat')
.then(function(resp) {
console.log('USER HEARTBEAT CALLED ')
})
.catch(function(error) {
console.log('USER HEARTBEAT ERROR ', error)
})
在被叫微服务中,我有以下代码:
server.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
next();
})
server.get('/usermicroservice/heartbeat', (req, res) => {
console.log('\n*** USER MICROSERVICE CALLED ***')
res.json({});
})
const PORT = 4210;
server.listen(PORT, () => {
console.log(`hsupp01 UserMicroservice server running on port: ${PORT}`)
})
我收到以下错误:
{ Error: connect ECONNREFUSED 127.0.0.1:4210
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 4210,
我可以使用相同的url从Postman访问被调用的微服务:
http://localhost:4210/usermicroservice/heartbeat
0
投票
投票
错误消息不捕获问题,但下面的代码必须在异步块中执行。
axios.get('http://localhost:4210/usermicroservice/heartbeat')
.then(function(resp) {
console.log('USER HEARTBEAT CALLED ')
})
.catch(function(error) {
console.log('USER HEARTBEAT ERROR ', error)
})