cleaner code for init of db pool
This commit is contained in:
13
src/main.rs
13
src/main.rs
@@ -14,17 +14,12 @@ async fn main() -> std::io::Result<()> {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
std::env::set_var("RUST_LOG", "debug");
|
std::env::set_var("RUST_LOG", "debug");
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let database_url = env::var("DATABASE_URL").expect("Put a DB url in the .env file dumbass");
|
let db_pool = init_dbpool().await;
|
||||||
let pool = sqlx::postgres::PgPoolOptions::new()
|
HttpServer::new(move || {
|
||||||
.max_connections(10)
|
|
||||||
.connect(database_url.as_str())
|
|
||||||
.await
|
|
||||||
.expect("No pool connection man :(");
|
|
||||||
HttpServer::new(|| {
|
|
||||||
App::new()
|
App::new()
|
||||||
.service(echo)
|
.service(echo)
|
||||||
.service(init_arrivals_scope())
|
.service(arrivals::init_arrivals_scope())
|
||||||
.app_data(web::Data::new(pool.clone()))
|
.app_data(web::Data::new(db_pool.clone()))
|
||||||
})
|
})
|
||||||
.bind(init_address())?
|
.bind(init_address())?
|
||||||
.run()
|
.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user