summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: af457792d3c0bfbfdc95d3df6862fab0bd9ae9e4 (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
30
31
32
33
34
35
mod structs;
mod routes;

use actix_web::{web, App, HttpServer};
use sqlx::mysql::{MySqlPool, MySqlPoolOptions};

#[derive(Clone)]
struct AppState {
    pool: MySqlPool,
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let pool: MySqlPool = MySqlPoolOptions::new()
        .max_connections(10)
        .connect(DB_URL)
        .await
        .unwrap();

    let app_state = AppState { pool };

    HttpServer::new(move || {
        App::new()
            .app_data(web::Data::new(app_state.clone()))
            .route("/", web::get().to(root))
            .service(routes::hello::hello_actix)
    })
    .bind(("127.0.0.1", 8000))?
    .run()
    .await
}

async fn root() -> String {
    String::from("Server is up and running")
}