feat(backend): add .env support and configuration priority

This commit is contained in:
spinline
2026-02-03 20:58:40 +03:00
parent 9d1aa8f7d2
commit a675203363
4 changed files with 58 additions and 15 deletions

54
Cargo.lock generated
View File

@@ -250,6 +250,7 @@ dependencies = [
"axum",
"bytes",
"clap",
"dotenvy",
"futures",
"mime_guess",
"quick-xml",
@@ -257,6 +258,7 @@ dependencies = [
"serde",
"serde_json",
"shared",
"thiserror 2.0.18",
"tokio",
"tokio-stream",
"tokio-util",
@@ -616,6 +618,12 @@ dependencies = [
"syn",
]
[[package]]
name = "dotenvy"
version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]]
name = "drain_filter_polyfill"
version = "0.1.3"
@@ -835,7 +843,7 @@ dependencies = [
"pin-project",
"serde",
"serde_json",
"thiserror",
"thiserror 1.0.69",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
@@ -856,7 +864,7 @@ dependencies = [
"pin-project",
"serde",
"serde_json",
"thiserror",
"thiserror 1.0.69",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
@@ -1239,7 +1247,7 @@ dependencies = [
"config",
"regex",
"serde",
"thiserror",
"thiserror 1.0.69",
"typed-builder",
]
@@ -1334,7 +1342,7 @@ dependencies = [
"serde-wasm-bindgen",
"serde_json",
"slotmap",
"thiserror",
"thiserror 1.0.69",
"tracing",
"wasm-bindgen",
"wasm-bindgen-futures",
@@ -1360,7 +1368,7 @@ dependencies = [
"serde",
"serde_json",
"serde_qs 0.13.0",
"thiserror",
"thiserror 1.0.69",
"tracing",
"wasm-bindgen",
"wasm-bindgen-futures",
@@ -1379,7 +1387,7 @@ dependencies = [
"leptos_reactive",
"serde",
"server_fn",
"thiserror",
"thiserror 1.0.69",
"tracing",
]
@@ -1542,7 +1550,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c51ebcefb2f0b9a5e0bea115532c8ae4215d1b01eff176d0f4ba4192895c2708"
dependencies = [
"serde",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@@ -1884,7 +1892,7 @@ dependencies = [
"quote",
"syn",
"syn_derive",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@@ -2042,7 +2050,7 @@ checksum = "0431a35568651e363364210c91983c1da5eb29404d9f0928b67d4ebcfa7d330c"
dependencies = [
"percent-encoding",
"serde",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@@ -2053,7 +2061,7 @@ checksum = "cd34f36fe4c5ba9654417139a9b3a20d2e1de6012ee678ad14d240c22c78d8d6"
dependencies = [
"percent-encoding",
"serde",
"thiserror",
"thiserror 1.0.69",
]
[[package]]
@@ -2106,7 +2114,7 @@ dependencies = [
"serde_json",
"serde_qs 0.12.0",
"server_fn_macro_default",
"thiserror",
"thiserror 1.0.69",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
@@ -2298,7 +2306,16 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
dependencies = [
"thiserror-impl 2.0.18",
]
[[package]]
@@ -2312,6 +2329,17 @@ dependencies = [
"syn",
]
[[package]]
name = "thiserror-impl"
version = "2.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "thread_local"
version = "1.1.9"
@@ -2583,7 +2611,7 @@ dependencies = [
"log",
"rand",
"sha1",
"thiserror",
"thiserror 1.0.69",
"utf-8",
]

5
backend/.env.example Normal file
View File

@@ -0,0 +1,5 @@
# rTorrent SCGI Socket Path
RTORRENT_SOCKET=/tmp/rtorrent.sock
# Backend Listen Port
PORT=3000

View File

@@ -23,3 +23,4 @@ rust-embed = "8.2"
mime_guess = "2.0"
shared = { path = "../shared" }
thiserror = "2.0.18"
dotenvy = "0.15.7"

View File

@@ -10,6 +10,7 @@ use axum::{
Router,
};
use clap::Parser;
use dotenvy::dotenv;
use shared::{AppEvent, Torrent};
use std::net::SocketAddr;
use std::sync::Arc;
@@ -33,16 +34,24 @@ pub struct AppState {
#[command(author, version, about, long_about = None)]
struct Args {
/// Path to rTorrent SCGI socket
#[arg(short, long, default_value = "/tmp/rtorrent.sock")]
#[arg(
short,
long,
env = "RTORRENT_SOCKET",
default_value = "/tmp/rtorrent.sock"
)]
socket: String,
/// Port to listen on
#[arg(short, long, default_value_t = 3000)]
#[arg(short, long, env = "PORT", default_value_t = 3000)]
port: u16,
}
#[tokio::main]
async fn main() {
// Load .env file
let _ = dotenv();
// initialize tracing with env filter (default to info)
tracing_subscriber::fmt()
.with_env_filter(