This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
skynet-webportal/packages/health-check/src/whatismyip.js

19 lines
470 B
JavaScript
Raw Normal View History

const http = require("http");
const { ipCheckService, ipRegex } = require("./utils");
const request = http.request({ host: ipCheckService }, (response) => {
response.on("data", (data) => {
if (ipRegex.test(data)) {
process.stdout.write(data);
} else {
throw new Error(`${ipCheckService} responded with invalid ip: "${data}"`);
}
});
});
request.on("error", (error) => {
throw error; // throw error to exit with code 1
});
request.end();