2022-10-04 11:06:48 +02:00
|
|
|
use std::{
|
|
|
|
sync::Arc,
|
|
|
|
};
|
2022-10-02 12:12:08 +02:00
|
|
|
|
2022-10-02 20:51:06 +02:00
|
|
|
mod error;
|
2022-10-04 11:07:14 +02:00
|
|
|
|
|
|
|
|
2022-10-04 11:06:48 +02:00
|
|
|
use clap::Parser;
|
2022-10-02 12:12:08 +02:00
|
|
|
|
2022-10-04 11:06:48 +02:00
|
|
|
use anyhow::Context;
|
2022-10-04 11:07:14 +02:00
|
|
|
|
2022-10-04 11:06:48 +02:00
|
|
|
use como_api::router::Api;
|
|
|
|
use como_infrastructure::{
|
|
|
|
configs::AppConfig, database::ConnectionPoolManager, register::ServiceRegister,
|
|
|
|
};
|
2022-10-04 11:07:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-02 12:12:08 +02:00
|
|
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
tracing::info!("Loading dotenv");
|
|
|
|
dotenv::dotenv()?;
|
|
|
|
|
2022-10-04 11:06:48 +02:00
|
|
|
let config = Arc::new(AppConfig::parse());
|
|
|
|
|
2022-10-02 12:12:08 +02:00
|
|
|
tracing_subscriber::registry()
|
|
|
|
.with(tracing_subscriber::EnvFilter::new(
|
|
|
|
std::env::var("RUST_LOG").unwrap_or_else(|_| {
|
2022-10-02 14:15:45 +02:00
|
|
|
"como_bin=debug,tower_http=debug,axum_extra=debug,hyper=info,mio=info,sqlx=info,async_graphql=debug"
|
|
|
|
.into()
|
2022-10-02 12:12:08 +02:00
|
|
|
}),
|
|
|
|
))
|
|
|
|
.with(tracing_subscriber::fmt::layer())
|
|
|
|
.init();
|
|
|
|
|
2022-10-04 11:06:48 +02:00
|
|
|
let pool = ConnectionPoolManager::new_pool(&config.database_url, true).await?;
|
2022-10-02 12:12:08 +02:00
|
|
|
|
2022-10-04 11:06:48 +02:00
|
|
|
let service_register = ServiceRegister::new(pool, config.clone());
|
2022-10-02 12:12:08 +02:00
|
|
|
|
2022-10-04 11:06:48 +02:00
|
|
|
Api::new(3001, &config.cors_origin, service_register.clone())
|
2022-10-02 12:12:08 +02:00
|
|
|
.await
|
2022-10-04 11:06:48 +02:00
|
|
|
.context("could not initialize API")?;
|
2022-10-02 12:12:08 +02:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|