mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-14 12:06:29 +00:00
Implement config from env
This commit is contained in:
parent
2254a0728c
commit
e00dee501b
3 changed files with 18 additions and 6 deletions
14
README.md
14
README.md
|
@ -100,9 +100,10 @@ $ cp nitter.example.conf nitter.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
Set your hostname, port, HMAC key, https (must be correct for cookies), and
|
Set your hostname, port, HMAC key, https (must be correct for cookies), and
|
||||||
Redis info in `nitter.conf`. To run Redis, either run
|
Redis info in `nitter.conf` or Environment Variables in format of
|
||||||
`redis-server --daemonize yes`, or `systemctl enable --now redis` (or
|
`NITTER_SECTION_KEY=xxxx` in upper case (for example: NITTER_SERVER_HOSTNAME=nitter.net).
|
||||||
redis-server depending on the distro). Run Nitter by executing `./nitter` or
|
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
|
using the systemd service below. You should run Nitter behind a reverse proxy
|
||||||
such as [Nginx](https://github.com/zedeus/nitter/wiki/Nginx) or
|
such as [Nginx](https://github.com/zedeus/nitter/wiki/Nginx) or
|
||||||
[Apache](https://github.com/zedeus/nitter/wiki/Apache) for security and
|
[Apache](https://github.com/zedeus/nitter/wiki/Apache) for security and
|
||||||
|
@ -125,6 +126,13 @@ docker build -t nitter:latest .
|
||||||
docker run -v $(pwd)/nitter.conf:/src/nitter.conf -d --network host 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).
|
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:
|
A prebuilt Docker image is provided as well:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Config can be set via Environment Variables in format of `NITTER_SECTION_KEY`.
|
||||||
|
# Environment Variables override nitter.conf.
|
||||||
[Server]
|
[Server]
|
||||||
hostname = "nitter.net" # for generating links, change this to your own domain/ip
|
hostname = "nitter.net" # for generating links, change this to your own domain/ip
|
||||||
title = "nitter"
|
title = "nitter"
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import parsecfg except Config
|
import parsecfg except Config
|
||||||
import types, strutils
|
import types, strutils, std/os
|
||||||
|
|
||||||
proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
|
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
|
if val.len == 0: return default
|
||||||
|
|
||||||
when T is int: parseInt(val)
|
when T is int: parseInt(val)
|
||||||
|
@ -11,7 +13,7 @@ proc get*[T](config: parseCfg.Config; section, key: string; default: T): T =
|
||||||
elif T is string: val
|
elif T is string: val
|
||||||
|
|
||||||
proc getConfig*(path: string): (Config, parseCfg.Config) =
|
proc getConfig*(path: string): (Config, parseCfg.Config) =
|
||||||
var cfg = loadConfig(path)
|
var cfg = try: loadConfig(path) except IOError: parseCfg.Config()
|
||||||
|
|
||||||
let conf = Config(
|
let conf = Config(
|
||||||
# Server
|
# Server
|
||||||
|
|
Loading…
Reference in a new issue