diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs index eb5af4c..0ff4827 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,22 +10,39 @@ mod errors; mod serve; mod spotify; -#[rocket::main] -async fn main() { - database::initialize_db().expect("failed to initialize_db"); +use tokio::runtime::Runtime; + +fn main() { + let runtime = Runtime::new().unwrap(); + let (client, connection) = runtime + .block_on(tokio_postgres::connect( + "host=127.0.0.1 user=spotify_intersect password=example dbname=track_db", + tokio_postgres::NoTls, + )) + .expect("failed to connect to database"); + unsafe { + database::_client = Some(client); + } + runtime.spawn(async { connection.await.unwrap() }); + + runtime + .block_on(database::initialize_db()) + .expect("failed to initialize_db"); println!("connected with db"); - rocket::ignite() - .mount( - "/", - routes![ - serve::token, - serve::get_tracks, - serve::match_users, - serve::get_users, - serve::create_lobby - ], + runtime + .block_on( + rocket::ignite() + .mount( + "/", + routes![ + serve::token, + serve::get_tracks, + serve::match_users, + serve::get_users, + serve::create_lobby + ], + ) + .launch(), ) - .launch() - .await .unwrap(); } |