Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get config from env #880

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ $ cp nitter.example.conf nitter.conf
```

Set your hostname, port, HMAC key, https (must be correct for cookies), and
Redis info in `nitter.conf`. To run Redis, either run
`redis-server --daemonize yes`, or `systemctl enable --now redis` (or
redis-server depending on the distro). Run Nitter by executing `./nitter` or
Redis info in `nitter.conf` or Environment Variables in format of
`NITTER_SECTION_KEY=xxxx` in upper case (for example: NITTER_SERVER_HOSTNAME=nitter.net).
To run Redis, either run `redis-server --daemonize yes`, or `systemctl enable --now redis`
(or redis-server depending on the distro). Run Nitter by executing `./nitter` or
using the systemd service below. You should run Nitter behind a reverse proxy
such as [Nginx](https://github.com/zedeus/nitter/wiki/Nginx) or
[Apache](https://github.com/zedeus/nitter/wiki/Apache) for security and
Expand All @@ -125,6 +126,13 @@ docker build -t nitter:latest .
docker run -v $(pwd)/nitter.conf:/src/nitter.conf -d --network host nitter:latest
```

or

```bash
docker build -t nitter:latest .
docker run -e NITTER_SERVER_ADDRESS=0.0.0.0 -e NITTER_SERVER_PORT=8080 -d --network host nitter:latest
```

Note: For ARM64, use this Dockerfile: [`Dockerfile.arm64`](https://github.com/zedeus/nitter/blob/master/Dockerfile.arm64).

A prebuilt Docker image is provided as well:
Expand Down
2 changes: 2 additions & 0 deletions nitter.example.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Config can be set via Environment Variables in format of `NITTER_SECTION_KEY`.
# Environment Variables override nitter.conf.
[Server]
hostname = "nitter.net" # for generating links, change this to your own domain/ip
title = "nitter"
Expand Down
8 changes: 5 additions & 3 deletions src/config.nim
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# SPDX-License-Identifier: AGPL-3.0-only
import parsecfg except Config
import types, strutils
import types, strutils, std/os

proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
let val = config.getSectionValue(section, key)
let envKey = "NITTER_" & section.toUpperAscii & "_" & key.toUpperAscii
let envVal = getEnv(envKey)
let val = if envVal.len == 0: config.getSectionValue(section, key) else: envVal
if val.len == 0: return default

when T is int: parseInt(val)
elif T is bool: parseBool(val)
elif T is string: val

proc getConfig*(path: string): (Config, parseCfg.Config) =
var cfg = loadConfig(path)
var cfg = try: loadConfig(path) except IOError: parseCfg.Config()

let conf = Config(
# Server
Expand Down