53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
use std::sync::Arc;
|
|
|
|
use axum::Router;
|
|
use tokio::{net::TcpListener, sync::Mutex};
|
|
use tracing::Level;
|
|
use tracing_subscriber::FmtSubscriber;
|
|
|
|
use wrbapp_server::routes::member::migrate::MigrationStore;
|
|
use wrbapp_server::routes::routes;
|
|
use wrbapp_server::{database, AppState};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
dotenvy::dotenv().ok();
|
|
|
|
// Initialize logging
|
|
let subscriber = FmtSubscriber::builder()
|
|
.with_max_level(Level::INFO)
|
|
.finish();
|
|
|
|
tracing::subscriber::set_global_default(subscriber)
|
|
.expect("Error while initialized tracing subscriber");
|
|
|
|
// Initialize database connection
|
|
database::apply_migrations()
|
|
.await
|
|
.expect("Database migrations failed");
|
|
|
|
let pool = database::connect()
|
|
.await
|
|
.expect("Database connection failed");
|
|
|
|
let migration_store = Arc::new(Mutex::new(MigrationStore::default()));
|
|
|
|
let app_state = AppState {
|
|
pool,
|
|
migration_store,
|
|
};
|
|
|
|
// Serve app
|
|
let app = Router::new().merge(routes()).with_state(app_state);
|
|
|
|
let listener = TcpListener::bind("127.0.0.1:3000")
|
|
.await
|
|
.expect("Error while initializing listener");
|
|
|
|
tracing::info!("Listening on {}", listener.local_addr().unwrap());
|
|
|
|
axum::serve(listener, app)
|
|
.await
|
|
.expect("Error while serving axum application");
|
|
}
|