From dbe8af8e64a8a0ce55672617ed240066adf88300 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 9 Mar 2021 20:54:17 +0100 Subject: feat: add pool on web server --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 594491f..0ef80bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,20 @@ +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<()> { - HttpServer::new(|| { - App::new().service( + 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!")), ) -- cgit v1.2.3-18-g5258