summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: acf8896cef4901e169d6157642abd9907daf5b94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
mod db;
mod error;
mod handlers;
mod models;

use axum::{
    Router,
    routing::{get, post},
};
use dotenvy::dotenv;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    dotenv().ok();
    let pool = db::connect().await?;
    let app = Router::new()
        .route("/", get(handlers::index))
        .route("/all", get(handlers::all))
        .route("/add", post(handlers::add))
        .route("/search", get(handlers::search))
        .with_state(pool);
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
    tracing::info!("listening at 0.0.0.0:3000");
    axum::serve(listener, app).await?;
    Ok(())
}