48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
mod api;
|
|
mod astronomy;
|
|
mod catalog;
|
|
mod config;
|
|
mod db;
|
|
mod filters;
|
|
mod jobs;
|
|
mod phd2;
|
|
mod weather;
|
|
|
|
use tower_http::cors::{Any, CorsLayer};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
// Initialize tracing
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "astronome=info,tower_http=info".into()),
|
|
)
|
|
.init();
|
|
|
|
let database_url = std::env::var("DATABASE_URL")
|
|
.unwrap_or_else(|_| "sqlite:///data/astronome.db".to_string());
|
|
|
|
tracing::info!("Connecting to database: {}", database_url);
|
|
let pool = db::init_db(&database_url).await?;
|
|
|
|
// Start background jobs
|
|
jobs::start_all_jobs(pool.clone());
|
|
|
|
// Build router
|
|
let cors = CorsLayer::new()
|
|
.allow_origin(Any)
|
|
.allow_methods(Any)
|
|
.allow_headers(Any);
|
|
|
|
let app = api::build_router(pool).layer(cors);
|
|
|
|
let bind_addr = "0.0.0.0:3001";
|
|
tracing::info!("Starting server on {}", bind_addr);
|
|
|
|
let listener = tokio::net::TcpListener::bind(bind_addr).await?;
|
|
axum::serve(listener, app).await?;
|
|
|
|
Ok(())
|
|
}
|