summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 51c2f6d1197cedf2e7554f8c1a16827e08238d0a (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
mod config;

use actix_web::{web, App, HttpResponse, HttpServer};
use dotenv::dotenv;
use tokio_postgres::NoTls;

use crate::config::Config;

#[actix_rt::main]
async fn main() -> std::io::Result<()> {
    dotenv().ok();

    let config = Config::from_env().unwrap();
    let pool = config.pg.create_pool(NoTls).unwrap();

    HttpServer::new(move || {
        App::new().data(pool.clone()).service(
            web::resource("/")
                .to(|| HttpResponse::Ok().body("Hello from Rust!")),
        )
    })
    .bind(format!("{}:{}", config.server.host, config.server.port))?
    .run()
    .await
}