[a] add proxy trust num
All checks were successful
Build and Push Docker Image / docker-build (push) Successful in 11s

This commit is contained in:
Sangelo 2024-10-21 17:35:04 +02:00
parent bcb75363f9
commit 97b4150a6a
3 changed files with 12 additions and 0 deletions

View file

@ -5,3 +5,4 @@ PLAUSIBLE_API_KEY="api_key_goes_here" # your plausible API key
ALLOWED_ORIGINS="https://example.com" # allowed CORS origins ALLOWED_ORIGINS="https://example.com" # allowed CORS origins
RATE_LIMIT_MINUTES=15 # the amount of time in minutes to rate limit RATE_LIMIT_MINUTES=15 # the amount of time in minutes to rate limit
RATE_LIMIT_REQUESTS=100 # amount of max. requests RATE_LIMIT_REQUESTS=100 # amount of max. requests
NUM_PROXY_TRUST=1 # amount of proxies to trust, set 0 to disable

View file

@ -12,6 +12,7 @@ PLAUSIBLE_API_KEY="api_key_goes_here" # your plausible API key
ALLOWED_ORIGINS="https://example.com" # allowed CORS origins ALLOWED_ORIGINS="https://example.com" # allowed CORS origins
RATE_LIMIT_MINUTES=15 # the amount of time in minutes to rate limit RATE_LIMIT_MINUTES=15 # the amount of time in minutes to rate limit
RATE_LIMIT_REQUESTS=100 # amount of max. requests 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. Don't change the `PORT` and `METRICS_PORT` values when running in a Docker Container.

10
main.js
View file

@ -69,6 +69,16 @@ app.use(
); );
// Rate limiting // 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_MINUTES = parseInt(process.env.RATE_LIMIT_MINUTES, 10) || 15;
const RATE_LIMIT_REQUESTS = const RATE_LIMIT_REQUESTS =
parseInt(process.env.RATE_LIMIT_REQUESTS, 10) || 100; parseInt(process.env.RATE_LIMIT_REQUESTS, 10) || 100;