main.rs 902 Bytes
Newer Older
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
1 2 3
#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] extern crate rocket;
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
4 5 6
#[macro_use] extern crate rocket_contrib;
#[macro_use] extern crate diesel;

Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
7
use trust_dns_client::client::SyncClient;
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
8 9
use trust_dns_client::tcp::TcpClientConnection;

Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
10
mod models;
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
11
mod config;
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
12
mod schema;
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
13
mod routes;
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
14

Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
15 16
use routes::users::*;
use routes::zones::*;
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
17

Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
18

Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
19 20
#[database("db")]
pub struct DbConn(diesel::SqliteConnection);
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
21

Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
22
type DnsClient = SyncClient<TcpClientConnection>;
23

Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
24

25 26
#[launch]
fn rocket() -> rocket::Rocket {
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
27
    let app_config = config::load("config.toml".into());
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
28
    println!("{:#?}", app_config);
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
29

Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
30
    let conn = TcpClientConnection::new(app_config.dns.server).unwrap();
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
31 32 33 34
    let client = SyncClient::new(conn);

    rocket::ignite()
        .manage(client)
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
35
        .manage(app_config)
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
36
        .attach(DbConn::fairing())
37
        .mount("/api/v1", routes![get_zone_records, create_auth_token, create_user])
Gaël Berthaud-Müller's avatar
Gaël Berthaud-Müller committed
38
}