Initial Commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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:3301";
|
||||
tracing::info!("Starting server on {}", bind_addr);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(bind_addr).await?;
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user