From 88176f89d4adef3394b77e4650de86567f536501 Mon Sep 17 00:00:00 2001 From: dappnodedev Date: Tue, 26 Dec 2023 16:31:09 +0100 Subject: [PATCH] Avoid fetching internal IP if env exists --- src/src/dappmanager/fetchInternalIp.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/src/dappmanager/fetchInternalIp.ts b/src/src/dappmanager/fetchInternalIp.ts index a1ae6e07..84396f04 100644 --- a/src/src/dappmanager/fetchInternalIp.ts +++ b/src/src/dappmanager/fetchInternalIp.ts @@ -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 { // 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 })