Skip to content

Commit

Permalink
Avoid fetching internal IP if env exists
Browse files Browse the repository at this point in the history
  • Loading branch information
dappnodedev committed Dec 26, 2023
1 parent fee7dcb commit 88176f8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/src/dappmanager/fetchInternalIp.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import ip from "ip";
import got from "got";
import { logs } from "../logs";
import { dappmanagerApiUrlGlobalEnvs, GLOBAL_ENVS_KEYS } from "../params";
import { GLOBAL_ENVS, dappmanagerApiUrlGlobalEnvs } from "../params";
import { config } from "../config";

export async function getInternalIpCached(): Promise<string> {
// internal IP is an optional feature for when NAT-Loopback is off
try {
const internalIp = await got(GLOBAL_ENVS_KEYS.INTERNAL_IP, {

const envInternalIp = process.env[GLOBAL_ENVS.INTERNAL_IP];

if (envInternalIp && ip.isV4Format(envInternalIp)) {

logs.info(`Using internal IP from ENV: ${envInternalIp}`);

config.internalIp = envInternalIp;
return envInternalIp;
}

logs.info(`Fetching internal IP from DAPPMANAGER: ${dappmanagerApiUrlGlobalEnvs}`);

const internalIp = await got(GLOBAL_ENVS.INTERNAL_IP, {
throwHttpErrors: true,
prefixUrl: dappmanagerApiUrlGlobalEnvs
})
Expand Down

0 comments on commit 88176f8

Please sign in to comment.