From 1c47fc2ba4ab72cbaf7b3397038ed370a8891650 Mon Sep 17 00:00:00 2001 From: cg-zhou Date: Wed, 26 Feb 2025 19:25:50 +0800 Subject: [PATCH 1/2] feat: Add IP_RANGES_FETCH_ENABLED environment variable This change adds a new environment variable to control whether IP ranges are fetched during application startup. When set to 'false', the initial fetch will be skipped, which can: 1. Speed up application startup 2. Avoid connectivity issues in environments with restricted internet access 3. Prevent startup failures when CloudFront or CloudFlare services are unreachable --- backend/index.js | 15 ++++++++++++++- docs/src/advanced-config/index.md | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/index.js b/backend/index.js index 551378251..196226ccd 100644 --- a/backend/index.js +++ b/backend/index.js @@ -3,6 +3,8 @@ const schema = require('./schema'); const logger = require('./logger').global; +const IP_RANGES_FETCH_ENABLED = process.env.IP_RANGES_FETCH_ENABLED !== 'false'; + async function appStart () { const migrate = require('./migrate'); const setup = require('./setup'); @@ -13,7 +15,18 @@ async function appStart () { return migrate.latest() .then(setup) .then(schema.getCompiledSchema) - .then(internalIpRanges.fetch) + .then(() => { + if (IP_RANGES_FETCH_ENABLED) { + logger.info('IP Ranges fetch is enabled'); + return internalIpRanges.fetch().catch(err => { + logger.error('IP Ranges fetch failed, continuing anyway:', err.message); + return Promise.resolve(); + }); + } else { + logger.info('IP Ranges fetch is disabled by environment variable'); + return Promise.resolve(); + } + }) .then(() => { internalCertificate.initTimer(); internalIpRanges.initTimer(); diff --git a/docs/src/advanced-config/index.md b/docs/src/advanced-config/index.md index 373fd08bb..4a7c260eb 100644 --- a/docs/src/advanced-config/index.md +++ b/docs/src/advanced-config/index.md @@ -161,6 +161,14 @@ The easy fix is to add a Docker environment variable to the Nginx Proxy Manager DISABLE_IPV6: 'true' ``` +## Disabling IP Ranges Fetch + +By default, NPM fetches IP ranges from CloudFront and Cloudflare during application startup. In environments with limited internet access or to speed up container startup, this fetch can be disabled: + +```yml + environment: + IP_RANGES_FETCH_ENABLED: 'false' +``` ## Custom Nginx Configurations From a394b25e61c997ead062783934cf99c7e5b71f6c Mon Sep 17 00:00:00 2001 From: cg-zhou Date: Wed, 26 Feb 2025 19:45:49 +0800 Subject: [PATCH 2/2] fix eslint error --- backend/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/index.js b/backend/index.js index 196226ccd..7e9a1842b 100644 --- a/backend/index.js +++ b/backend/index.js @@ -18,7 +18,7 @@ async function appStart () { .then(() => { if (IP_RANGES_FETCH_ENABLED) { logger.info('IP Ranges fetch is enabled'); - return internalIpRanges.fetch().catch(err => { + return internalIpRanges.fetch().catch((err) => { logger.error('IP Ranges fetch failed, continuing anyway:', err.message); return Promise.resolve(); });