我有一些后端服务,这些服务只能通过API网关服务器调用。 后端服务在Spring rest服务中,API GateWay是一个节点服务器。这两个服务器在本地运行在不同的端口上(后端:8080,节点:3000)。
如何从我的节点服务器请求后端服务?
如果它们都公开了其余的API,则可以使用内置的http模块进行通信
require('http');
var options = {
host: 'www.google.com',
port: 80,
path: '/index.html'
};
http.get(options, function(res) {
console.log("Got response: " + res.statusCode);
res.on("data", function(chunk) {
console.log("BODY: " + chunk);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
但是我建议使用诸如superagent或axios之类的库