feat(backend): add .env support and configuration priority
This commit is contained in:
5
backend/.env.example
Normal file
5
backend/.env.example
Normal file
@@ -0,0 +1,5 @@
|
||||
# rTorrent SCGI Socket Path
|
||||
RTORRENT_SOCKET=/tmp/rtorrent.sock
|
||||
|
||||
# Backend Listen Port
|
||||
PORT=3000
|
||||
@@ -23,3 +23,4 @@ rust-embed = "8.2"
|
||||
mime_guess = "2.0"
|
||||
shared = { path = "../shared" }
|
||||
thiserror = "2.0.18"
|
||||
dotenvy = "0.15.7"
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user