use std::{ env::{self, current_dir}, sync::Arc, }; mod error; use axum::{ extract::Extension, http::{Method, StatusCode}, response::{Html, IntoResponse}, routing::{get, post}, Json, Router, }; use axum_extra::extract::cookie::Key; use clap::Parser; use anyhow::Context; use axum_sessions::{ async_session::MemoryStore, extractors::{ReadableSession, WritableSession}, SessionLayer, }; use como_api::router::Api; use como_infrastructure::{ configs::AppConfig, database::ConnectionPoolManager, register::ServiceRegister, }; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use sqlx::PgPool; use tower_http::{cors::CorsLayer, trace::TraceLayer}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() -> anyhow::Result<()> { tracing::info!("Loading dotenv"); dotenv::dotenv()?; let config = Arc::new(AppConfig::parse()); tracing_subscriber::registry() .with(tracing_subscriber::EnvFilter::new( std::env::var("RUST_LOG").unwrap_or_else(|_| { "como_bin=debug,tower_http=debug,axum_extra=debug,hyper=info,mio=info,sqlx=info,async_graphql=debug" .into() }), )) .with(tracing_subscriber::fmt::layer()) .init(); let pool = ConnectionPoolManager::new_pool(&config.database_url, true).await?; let service_register = ServiceRegister::new(pool, config.clone()); Api::new(3001, &config.cors_origin, service_register.clone()) .await .context("could not initialize API")?; Ok(()) }