I am using the request package from NPM to handle some internal communication between services. I have also set the DNS server to the correct one (using Hashicorp Consul as my SD and DNS).
I can do a dig on my local machine (where the services are running) to the consul DNS server and I am able to get back the correct response (an IP and port number.
How I setup DNS in my app.js file6
dns.setServers([ `${config.consul.host}:8600` ]);
Set in a different file than app.js
options = {
baseUrl: `http://auth.service.consul`,
json: { '': '' },
headers: { authorization: '' }
};
Same file as options above
request.post(req.path, options, (error, response, body) => {
console.log(error);
if (error) throw error;
res.status(response.statusCode).json(body);
});
Error message:
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'auth.service.consul',
host: 'auth.service.consul',
port: 80 }
I am wanting to be able to make requests to the 'auth' service when using Consul as my DNS server. I currently have a very hacky way of doing this but really would like to use DNS.
I did find this but it is pertaining to the axios package not the request one I am trying to use even though it produces the same error the solution there didn't help. Consul service discovery with DNS on Nodejs