From 03919c88c6c69c91cce3639917c4f91ffba19ddd Mon Sep 17 00:00:00 2001 From: Muhamad Aji Wibisono Date: Tue, 10 Jun 2025 22:52:19 +0700 Subject: [PATCH] fix: config loading into run --- surfsense_backend/.env.example | 63 +++++++++++++++++----------------- surfsense_backend/main.py | 5 ++- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/surfsense_backend/.env.example b/surfsense_backend/.env.example index 336bf28..e0b53ad 100644 --- a/surfsense_backend/.env.example +++ b/surfsense_backend/.env.example @@ -54,36 +54,35 @@ STT_SERVICE_API_BASE="" # --- Uvicorn Server Configuration --- # Full documentation for Uvicorn options can be found at: https://www.uvicorn.org/#command-line-options -UVICORN_HOST="0.0.0.0" # Host to bind (default: 0.0.0.0) -UVICORN_PORT=8000 # Port to bind (default: 8000) -UVICORN_LOG_LEVEL="info" # Log level (critical, error, warning, info, debug, trace) +UVICORN_HOST="0.0.0.0" +UVICORN_PORT=8000 +UVICORN_LOG_LEVEL=info -# --- Advanced Uvicorn Options (uncomment to use) --- -# UVICORN_PROXY_HEADERS=false # Enable proxy headers (true/false) -# UVICORN_FORWARDED_ALLOW_IPS="127.0.0.1" # Comma-separated list of IPs to trust with proxy headers -# UVICORN_WORKERS=1 # Number of worker processes -# UVICORN_ACCESS_LOG=true # Access log (true/false) -# UVICORN_LOOP="auto" # Event loop implementation (auto, asyncio, uvloop) -# UVICORN_HTTP="auto" # HTTP protocol implementation (auto, h11, httptools) -# UVICORN_WS="auto" # WebSocket protocol implementation (auto, none, websockets, wsproto) -# UVICORN_LIFESPAN="auto" # Lifespan implementation (auto, on, off) -# UVICORN_ENV_FILE=".env" # Environment configuration file -# UVICORN_LOG_CONFIG="" # Logging configuration file (YAML/JSON/dict) -# UVICORN_SERVER_HEADER=true # Enable server header (true/false) -# UVICORN_DATE_HEADER=true # Enable date header (true/false) -# UVICORN_LIMIT_CONCURRENCY= # Maximum number of concurrent connections or tasks -# UVICORN_LIMIT_MAX_REQUESTS= # Maximum number of requests a worker will process before restarting -# UVICORN_TIMEOUT_KEEP_ALIVE=5 # Timeout for keep-alive connections (seconds) -# UVICORN_TIMEOUT_NOTIFY=30 # Timeout for graceful shutdown (seconds) -# UVICORN_SSL_KEYFILE="" # SSL key file (path) -# UVICORN_SSL_CERTFILE="" # SSL certificate file (path) -# UVICORN_SSL_KEYFILE_PASSWORD="" # SSL key file password -# UVICORN_SSL_VERSION="" # SSL version to use -# UVICORN_SSL_CERT_REQS="" # Whether client certificate is required (none, optional, required) -# UVICORN_SSL_CA_CERTS="" # CA certificates file -# UVICORN_SSL_CIPHERS="" # Ciphers to use -# UVICORN_HEADERS="" # List of custom default HTTP response headers (comma-separated, e.g. X-Frame-Options:DENY,X-Content-Type-Options:nosniff) -# UVICORN_USE_COLORS=true # Enable colorized logging output (true/false) -# UVICORN_UDS="" # Bind to a UNIX domain socket (overrides host/port) -# UVICORN_FD="" # Bind to socket from this file descriptor -# UVICORN_ROOT_PATH="" # Root path for ASGI applications submounted below a given URL path +# --- Advanced Uvicorn Options --- +# UVICORN_PROXY_HEADERS=false +# UVICORN_FORWARDED_ALLOW_IPS="127.0.0.1" +# UVICORN_WORKERS=1 +# UVICORN_ACCESS_LOG=true +# UVICORN_LOOP="auto" +# UVICORN_HTTP="auto" +# UVICORN_WS="auto" +# UVICORN_LIFESPAN="auto" +# UVICORN_LOG_CONFIG="" +# UVICORN_SERVER_HEADER=true +# UVICORN_DATE_HEADER=true +# UVICORN_LIMIT_CONCURRENCY= +# UVICORN_LIMIT_MAX_REQUESTS= +# UVICORN_TIMEOUT_KEEP_ALIVE=5 +# UVICORN_TIMEOUT_NOTIFY=30 +# UVICORN_SSL_KEYFILE="" +# UVICORN_SSL_CERTFILE="" +# UVICORN_SSL_KEYFILE_PASSWORD="" +# UVICORN_SSL_VERSION="" +# UVICORN_SSL_CERT_REQS="" +# UVICORN_SSL_CA_CERTS="" +# UVICORN_SSL_CIPHERS="" +# UVICORN_HEADERS="" +# UVICORN_USE_COLORS=true +# UVICORN_UDS="" +# UVICORN_FD="" +# UVICORN_ROOT_PATH="" diff --git a/surfsense_backend/main.py b/surfsense_backend/main.py index 79cc1bc..2884cf3 100644 --- a/surfsense_backend/main.py +++ b/surfsense_backend/main.py @@ -17,6 +17,5 @@ if __name__ == "__main__": parser.add_argument("--reload", action="store_true", help="Enable hot reloading") args = parser.parse_args() - config = uvicorn.Config(**load_uvicorn_config(args)) - - uvicorn.run(config) + config_kwargs = load_uvicorn_config(args) + uvicorn.run(**config_kwargs)