Work behind reverse proxy

This commit is contained in:
Minecon724 2025-06-15 15:34:32 +02:00
commit 080f8f6b1a
Signed by: Minecon724
GPG key ID: A02E6E67AB961189
4 changed files with 17 additions and 4 deletions

View file

@ -5,4 +5,10 @@ DATABASE_URL=postgres://kemal:kemal@[fc6c:b484:25b1:d25d::1]/invidious
QUART_SECRET_KEY=0359e1c42e06fbaa284567ef7dc0faae
# Any Invidious instance
ALTERNATIVE_INSTANCE_URL=https://redirect.invidious.io
ALTERNATIVE_INSTANCE_URL=https://redirect.invidious.io
# The amount of reverse proxies a request from a client is proxied through
PROXY_HOPS=0
# Whether to use RFC7239
PROXY_MODERN=false

View file

@ -68,4 +68,4 @@ ENTRYPOINT ["./entrypoint.sh"]
# Define the default command to run the application
# This is passed as arguments to the entrypoint script
CMD ["granian", "--interface", "asgi", "src.invidious_export_server:app"]
CMD ["granian", "--host", "0.0.0.0", "--interface", "asgi", "src.invidious_export_server:fixed_app"]

View file

@ -21,7 +21,7 @@ dependencies = [
packages = [{include = "invidious_export_server", from = "src"}]
[tool.poetry.scripts]
start = "invidious_export_server:run"
debug = "invidious_export_server:run_debug"
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]

View file

@ -2,6 +2,7 @@ from quart import Quart, redirect, request, render_template, make_response, url_
from quart_db import QuartDB
from quart_bcrypt import Bcrypt
from quart_rate_limiter import RateLimiter
from hypercorn.middleware import ProxyFixMiddleware
from os import environ
from dotenv import load_dotenv
@ -14,6 +15,8 @@ load_dotenv()
app.config.from_prefixed_env()
app.config['QUART_DB_DATABASE_URL'] = environ.get("DATABASE_URL")
app.config['ALTERNATIVE_INSTANCE_URL'] = environ.get("ALTERNATIVE_INSTANCE_URL", "https://redirect.invidious.io")
app.config['PROXY_MODERN'] = environ.get("PROXY_MODERN", "false").lower() == 'true'
app.config['PROXY_HOPS'] = int(environ.get("PROXY_HOPS", 0))
db = QuartDB(app)
bcrypt = Bcrypt(app)
@ -21,6 +24,10 @@ rate_limiter = RateLimiter(app)
blueprints.register_all(app)
fixed_app = ProxyFixMiddleware(app,
mode='modern' if app.config['PROXY_MODERN'] else 'legacy',
trusted_hops=app.config['PROXY_HOPS'])
@app.context_processor
def add_variables():
return {
@ -55,5 +62,5 @@ def favicon():
def health():
return 'OK'
def run() -> None:
def run_debug() -> None:
app.run(debug=True)