diff --git a/.env.example b/.env.example index 092855e..6a4ca57 100644 --- a/.env.example +++ b/.env.example @@ -5,3 +5,4 @@ PLAUSIBLE_API_KEY="api_key_goes_here" # your plausible API key ALLOWED_ORIGINS="https://example.com" # allowed CORS origins RATE_LIMIT_MINUTES=15 # the amount of time in minutes to rate limit RATE_LIMIT_REQUESTS=100 # amount of max. requests +NUM_PROXY_TRUST=1 # amount of proxies to trust, set 0 to disable diff --git a/README.md b/README.md index 66fd5bb..9897806 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ PLAUSIBLE_API_KEY="api_key_goes_here" # your plausible API key ALLOWED_ORIGINS="https://example.com" # allowed CORS origins RATE_LIMIT_MINUTES=15 # the amount of time in minutes to rate limit RATE_LIMIT_REQUESTS=100 # amount of max. requests +NUM_PROXY_TRUST=1 # amount of proxies to trust, set 0 to disable ``` Don't change the `PORT` and `METRICS_PORT` values when running in a Docker Container. diff --git a/main.js b/main.js index 683a003..260c741 100644 --- a/main.js +++ b/main.js @@ -69,6 +69,16 @@ app.use( ); // Rate limiting + +const NUM_PROXY_TRUST = parseInt(process.env.NUM_PROXY_TRUST, 10) || 1; + +if (NUM_PROXY_TRUST > 0) { + app.set("trust proxy", NUM_PROXY_TRUST); +} else { + // Do not set proxy trust if NUM_PROXY_TRUST is 0 + return; +} + const RATE_LIMIT_MINUTES = parseInt(process.env.RATE_LIMIT_MINUTES, 10) || 15; const RATE_LIMIT_REQUESTS = parseInt(process.env.RATE_LIMIT_REQUESTS, 10) || 100;