From acc53bafc9af5704cf31413b2e93b57b36ff26ad Mon Sep 17 00:00:00 2001 From: meliurwen Date: Wed, 31 Mar 2021 02:40:53 +0200 Subject: [PATCH] Added Nitter --- .gitignore | 2 +- build.sh => build.bibliogram.sh | 0 build.nitter.sh | 17 +++++++++ config.js => config/bibliogram.config.js | 0 config/nitter.conf | 39 ++++++++++++++++++++ docker-compose.yml | 14 ++++++- nginx.env.example | 4 ++ nginx/Dockerfile | 3 ++ nginx/root/etc/nginx/conf.d/default.template | 25 +++++++++++++ 9 files changed, 102 insertions(+), 2 deletions(-) rename build.sh => build.bibliogram.sh (100%) create mode 100755 build.nitter.sh rename config.js => config/bibliogram.config.js (100%) create mode 100644 config/nitter.conf diff --git a/.gitignore b/.gitignore index c26842c..540d660 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.env bibliogram/ -config.js +config/ diff --git a/build.sh b/build.bibliogram.sh similarity index 100% rename from build.sh rename to build.bibliogram.sh diff --git a/build.nitter.sh b/build.nitter.sh new file mode 100755 index 0000000..21c35f1 --- /dev/null +++ b/build.nitter.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +REPO_URL=https://github.com/zedeus/nitter.git +REPO_DIR_PATH=nitter + +# If repo exists update, else clone it +if [ -d "$REPO_DIR_PATH" ]; then + # Save the root dir path, enter the repo, pull new changes and come back + ROOT_DIR=$(pwd) + cd "$REPO_DIR_PATH" + git pull + cd "$ROOT_DIR" +else + git clone "$REPO_URL" "$REPO_DIR_PATH" +fi diff --git a/config.js b/config/bibliogram.config.js similarity index 100% rename from config.js rename to config/bibliogram.config.js diff --git a/config/nitter.conf b/config/nitter.conf new file mode 100644 index 0000000..d6543e4 --- /dev/null +++ b/config/nitter.conf @@ -0,0 +1,39 @@ + +[Server] +address = "0.0.0.0" +port = 8080 +https = false # disable to enable cookies when not using https +staticDir = "./public" +title = "nitter" +hostname = "nitter.net" + +[Cache] +listMinutes = 240 # how long to cache list info (not the tweets, so keep it high) +rssMinutes = 10 # how long to cache rss queries +redisHost = "localhost" +redisPort = 6379 +redisConnections = 20 # connection pool size +redisMaxConnections = 30 +# max, new connections are opened when none are available, but if the pool size +# goes above this, they're closed when released. don't worry about this unless +# you receive tons of requests per second + +[Config] +hmacKey = "secretkey" # random key for cryptographic signing of video urls +base64Media = false # use base64 encoding for proxied media urls +tokenCount = 10 +# minimum amount of usable tokens. tokens are used to authorize API requests, +# but they expire after ~1 hour, and have a limit of 187 requests. +# the limit gets reset every 15 minutes, and the pool is filled up so there's +# always at least $tokenCount usable tokens. again, only increase this if +# you receive major bursts all the time + +# Change default preferences here, see src/prefs_impl.nim for a complete list +[Preferences] +theme = "Nitter" +replaceTwitter = "nitter.net" +replaceYouTube = "invidio.us" +replaceInstagram = "" +proxyVideos = true +hlsPlayback = false +infiniteScroll = false diff --git a/docker-compose.yml b/docker-compose.yml index dd68244..707a63d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,7 +26,19 @@ services: - "10407" volumes: - db:/app/db - - ./config.js:/app/config.js + - .config/bibliogram.config.js:/app/config.js + networks: + - bibliogram + + nitter: + build: + context: nitter/ + container_name: ${NI_CONTAINER_NAME:-nitter} + restart: ${NI_RESTART:-unless-stopped} + expose: + - "8080" + volumes: + - .config/nitter.conf:/src/nitter.conf networks: - bibliogram diff --git a/nginx.env.example b/nginx.env.example index 41eb7b2..3239033 100644 --- a/nginx.env.example +++ b/nginx.env.example @@ -6,6 +6,10 @@ BG_HOSTNAME= BG_ADDR=bibliogram BG_PORT=10407 +BG_HOSTNAME= +NI_ADDR=nitter +NI_PORT=8080 + NGINX_LISTEN_PORT=80 # Reverse-proxy and certbot diff --git a/nginx/Dockerfile b/nginx/Dockerfile index d29975b..d1254fb 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -10,6 +10,9 @@ COPY root/ / ENV BG_HOSTNAME= ENV BG_ADDR=bibliogram ENV BG_PORT=10407 +ENV BG_HOSTNAME= +ENV NI_ADDR=nitter +ENV NI_PORT=8080 ENV NGINX_LISTEN_PORT=80 ENTRYPOINT ["/entrypoint.sh"] diff --git a/nginx/root/etc/nginx/conf.d/default.template b/nginx/root/etc/nginx/conf.d/default.template index 57386ae..6d87c1a 100644 --- a/nginx/root/etc/nginx/conf.d/default.template +++ b/nginx/root/etc/nginx/conf.d/default.template @@ -13,6 +13,13 @@ upstream bibliogram { server ${BG_ADDR}:${BG_PORT}; } +upstream nitter { + # Cannot connect to network of this container + server 127.0.0.1 down; + ## Can be connected with the network + server ${NI_ADDR}:${NI_PORT}; +} + server { # This is a catch-all hostname (it will never trigger on a real hostname). # If an access by IP or by an unhandled domain linking to this IP is tried, @@ -55,3 +62,21 @@ server { } } + +server { + listen ${NGINX_LISTEN_PORT}; + server_name ${NI_HOSTNAME}; + + # Disable do not add the server version in the header + server_tokens off; + + location / { + proxy_pass http://nitter; + } + + location = /robots.txt { + add_header Content-Type text/plain; + return 200 "User-agent: *\nDisallow: /\n"; + } + +}