48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
use std::error::Error;
|
|
|
|
use axum::Router;
|
|
use sqlx::PgPool;
|
|
use tokio::net::TcpListener;
|
|
|
|
mod api;
|
|
mod config;
|
|
mod database;
|
|
mod error;
|
|
mod logs;
|
|
mod persons;
|
|
mod quotes;
|
|
mod tags;
|
|
mod users;
|
|
mod web;
|
|
|
|
/// The string to be returned alongside HTTP 500
|
|
const ISE_MSG: &str = "Internal server error";
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct MnemoState {
|
|
pool: PgPool,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn Error>> {
|
|
config::dotenv()?;
|
|
config::env_logger()?;
|
|
|
|
let pool = config::init_pool().await?;
|
|
sqlx::migrate!("src/database/migrations").run(&pool).await?;
|
|
log::info!("Migrations applied successfully.");
|
|
users::auth::init_password_dummies();
|
|
users::setup::initialise_reserved_users_if_needed(&pool).await?;
|
|
|
|
let port = config::port()?;
|
|
let r = Router::new()
|
|
.merge(api::api_router())
|
|
.merge(web::web_router())
|
|
.with_state(MnemoState { pool });
|
|
let l = TcpListener::bind(format!("0.0.0.0:{port}")).await?;
|
|
log::info!("Listener bound to {}", l.local_addr()?);
|
|
|
|
axum::serve(l, r).await?;
|
|
Ok(())
|
|
}
|