summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: b297f14894c73fa6c485a9b639a2dde159e86d46 (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
36
37
38
39
40
41
42
43
44
45
#[macro_use]
extern crate rocket;
#[macro_use]
extern crate lazy_static;
mod database;
mod errors;
mod serve;
mod spotify;

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");
    runtime
        .block_on(
            rocket::ignite()
                .mount(
                    "/",
                    routes![
                        serve::token,
                        serve::get_tracks,
                        serve::match_users,
                        serve::get_users,
                        serve::create_lobby
                    ],
                )
                .launch(),
        )
        .unwrap();
}