From a85994387191f5a860536b411d422a2aecf2e820 Mon Sep 17 00:00:00 2001 From: 3nprob <74199244+3nprob@users.noreply.github.com> Date: Wed, 23 Jun 2021 21:17:16 +0000 Subject: [PATCH] Expand configuration (#368) * Allow configuring httpMaxConns default: 100 * Allow setting NITTER_CONF_FILE path env var Co-authored-by: 3nprob <3nprob@3nprob> --- nitter.conf | 1 + src/config.nim | 2 ++ src/nitter.nim | 5 +++-- src/types.nim | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nitter.conf b/nitter.conf index d6d860b..7858a89 100644 --- a/nitter.conf +++ b/nitter.conf @@ -2,6 +2,7 @@ address = "0.0.0.0" port = 8080 https = false # disable to enable cookies when not using https +httpMaxConnections = 100 staticDir = "./public" title = "nitter" hostname = "nitter.net" diff --git a/src/config.nim b/src/config.nim index f24e9aa..97a43d5 100644 --- a/src/config.nim +++ b/src/config.nim @@ -16,6 +16,8 @@ proc getConfig*(path: string): (Config, parseCfg.Config) = address: cfg.get("Server", "address", "0.0.0.0"), port: cfg.get("Server", "port", 8080), useHttps: cfg.get("Server", "https", true), + httpMaxConns: cfg.get("Server", "httpMaxConnections", 100), + title: cfg.get("Server", "title", "Nitter"), hostname: cfg.get("Server", "hostname", "nitter.net"), staticDir: cfg.get("Server", "staticDir", "./public"), diff --git a/src/nitter.nim b/src/nitter.nim index 3eee87b..20cf8df 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -1,6 +1,7 @@ import asyncdispatch, strformat from net import Port from htmlgen import a +from os import getEnv import jester @@ -12,7 +13,7 @@ import routes/[ const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances" -const configPath {.strdefine.} = "./nitter.conf" +let configPath = getEnv("NITTER_CONF_FILE", "./nitter.conf") let (cfg, fullCfg) = getConfig(configPath) when defined(release): @@ -28,7 +29,7 @@ updateDefaultPrefs(fullCfg) setCacheTimes(cfg) setHmacKey(cfg.hmacKey) setProxyEncoding(cfg.base64Media) -setMaxHttpConns(100) +setMaxHttpConns(cfg.httpMaxConns) waitFor initRedisPool(cfg) stdout.write &"Connected to Redis at {cfg.redisHost}:{cfg.redisPort}\n" diff --git a/src/types.nim b/src/types.nim index 00df8fd..de3d325 100644 --- a/src/types.nim +++ b/src/types.nim @@ -204,6 +204,7 @@ type address*: string port*: int useHttps*: bool + httpMaxConns*: int title*: string hostname*: string staticDir*: string