mirror of
https://github.com/thegeneralist01/archivr
synced 2026-10-09 12:55:00 +02:00
feat(auth): add auth_db_path to AppState, registry, and main.rs
This commit is contained in:
parent
86e8049f1b
commit
a4239ba5fc
3 changed files with 191 additions and 154 deletions
|
|
@ -12,10 +12,19 @@ async fn main() -> Result<()> {
|
|||
.nth(1)
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|| PathBuf::from("archivr-server.toml"));
|
||||
let registry = registry::load_registry(&config_path)?;
|
||||
let app = routes::app(registry.clone());
|
||||
|
||||
// Bind address priority: ARCHIVR_BIND env var > TOML bind field > default loopback.
|
||||
let registry = registry::load_registry(&config_path)?;
|
||||
|
||||
// Auth DB lives next to the config file unless overridden in the TOML.
|
||||
let auth_db_path = registry.auth_db_path.clone().unwrap_or_else(|| {
|
||||
config_path
|
||||
.parent()
|
||||
.unwrap_or_else(|| std::path::Path::new("."))
|
||||
.join("archivr-auth.sqlite")
|
||||
});
|
||||
|
||||
let app = routes::app(registry.clone(), auth_db_path.clone());
|
||||
|
||||
let bind_str = std::env::var("ARCHIVR_BIND")
|
||||
.ok()
|
||||
.or_else(|| registry.bind.clone())
|
||||
|
|
@ -25,15 +34,6 @@ async fn main() -> Result<()> {
|
|||
.parse()
|
||||
.with_context(|| format!("invalid bind address: {bind_str}"))?;
|
||||
|
||||
// Warn when the server is reachable beyond localhost — it has no authentication.
|
||||
if !addr.ip().is_loopback() {
|
||||
eprintln!(
|
||||
"warn: archivr-server is bound to {addr} — \
|
||||
this server has no authentication. \
|
||||
Only expose it on a trusted network."
|
||||
);
|
||||
}
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(addr).await?;
|
||||
println!("archivr-server listening on http://{addr}");
|
||||
axum::serve(listener, app).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue