summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: b4d7567f03c12397d65c9fa5dac65352f3007969 (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
28
29
use std::env;

use dotenvy::dotenv;
use sqlx::sqlite::SqlitePoolOptions;

mod db;
mod error;
mod handlers;

#[tokio::main]
async fn main() {
    dotenv().ok();
    let pool = SqlitePoolOptions::new()
        .connect(
            &env::var("DATABASE_URL").expect("Failed to get environment variable DATABASE_URL"),
        )
        .await
        .expect("Failed to connect to database");

    sqlx::migrate!()
        .run(&pool)
        .await
        .expect("Failed to run migrations");

    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, handlers::router(pool).await.into_make_service())
        .await
        .unwrap();
}