forked from boos/BoosAPI
feat: complete user login admin keys and deployment docs
This commit is contained in:
+82
-6
@@ -1,19 +1,76 @@
|
||||
use axum::serve;
|
||||
use boosapi::{config::AppConfig, db, AppState};
|
||||
use clap::Parser;
|
||||
use std::ffi::OsString;
|
||||
use std::net::SocketAddr;
|
||||
use tokio::signal;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(
|
||||
name = "boosapi",
|
||||
version,
|
||||
author,
|
||||
about = "AI API Gateway — Rust rewrite of BoosAPI"
|
||||
)]
|
||||
struct Cli {
|
||||
/// Config file path
|
||||
#[arg(short, long, default_value = "config.toml")]
|
||||
config: String,
|
||||
|
||||
/// Host to bind to
|
||||
#[arg(long)]
|
||||
host: Option<String>,
|
||||
|
||||
/// Port to listen on
|
||||
#[arg(short, long)]
|
||||
port: Option<u16>,
|
||||
|
||||
/// Log level (trace, debug, info, warn, error)
|
||||
#[arg(long)]
|
||||
log_level: Option<String>,
|
||||
|
||||
/// Only run database migrations and exit
|
||||
#[arg(long)]
|
||||
migrate_only: bool,
|
||||
|
||||
/// Load and validate configuration, then exit
|
||||
#[arg(long)]
|
||||
check_config: bool,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
// Initialize tracing
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.init();
|
||||
let args = Cli::parse_from(normalize_legacy_args());
|
||||
|
||||
// Load config
|
||||
let config = AppConfig::load()?;
|
||||
tracing::info!("Loaded configuration");
|
||||
let mut config = AppConfig::load_from_file(&args.config)?;
|
||||
|
||||
// Apply CLI overrides
|
||||
if let Some(host) = args.host {
|
||||
config.server.host = host;
|
||||
}
|
||||
if let Some(port) = args.port {
|
||||
config.server.port = port;
|
||||
}
|
||||
if let Some(level) = args.log_level {
|
||||
config.server.log_level = level;
|
||||
}
|
||||
|
||||
if args.check_config {
|
||||
println!("Configuration is valid.");
|
||||
println!("Server: {}:{}", config.server.host, config.server.port);
|
||||
println!("Database URL: {}", config.db.url);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Initialize tracing
|
||||
let filter = EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| EnvFilter::new(&config.server.log_level));
|
||||
|
||||
tracing_subscriber::fmt().with_env_filter(filter).init();
|
||||
|
||||
tracing::info!("Loaded configuration from {}", args.config);
|
||||
|
||||
// Create database pool
|
||||
let pool = db::create_pool(&config.db.url, config.db.max_connections).await?;
|
||||
@@ -23,6 +80,11 @@ async fn main() -> anyhow::Result<()> {
|
||||
sqlx::migrate!("./migrations").run(&pool).await?;
|
||||
tracing::info!("Database migrations applied");
|
||||
|
||||
if args.migrate_only {
|
||||
tracing::info!("Migration only mode requested. Exiting.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Build app state
|
||||
let state = AppState::new(config.clone(), pool);
|
||||
if let Err(err) = state.comfyui.start().await {
|
||||
@@ -51,6 +113,20 @@ async fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn normalize_legacy_args() -> Vec<OsString> {
|
||||
std::env::args_os()
|
||||
.map(|arg| {
|
||||
if arg == "-help" {
|
||||
OsString::from("--help")
|
||||
} else if arg == "-version" {
|
||||
OsString::from("--version")
|
||||
} else {
|
||||
arg
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn shutdown_signal() {
|
||||
let ctrl_c = async {
|
||||
signal::ctrl_c()
|
||||
|
||||
Reference in New Issue
Block a user