aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 4876b35c04cf683a1b1125f0b75d1de60acb9dd2 (plain) (blame)
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
#![feature(plugin, custom_derive)]
#![plugin(rocket_codegen)]

#[macro_use] extern crate bart_derive;
#[macro_use] extern crate diesel_codegen;
#[macro_use] extern crate diesel;
#[macro_use] extern crate serde_derive;

extern crate dotenv;
extern crate r2d2;
extern crate r2d2_diesel;
extern crate rocket;
extern crate rocket_contrib;

#[macro_use] mod utils;
mod models;
mod schema;
mod controllers;
use controllers::home_controller;
use controllers::posts_controller;

fn main() {
    if let Ok(dburl) = dotenv::var("DATABASE_URL") {
        rocket::ignite()
            .manage(utils::init_db_pool(&dburl))
            .mount("/",
                routes![
                    home_controller::index,
                    home_controller::index_json,
                    home_controller::public_file])
            .mount("/posts",
                routes![
                    posts_controller::new,
                    posts_controller::create,
                    posts_controller::show,
                    posts_controller::edit,
                    posts_controller::update,
                    posts_controller::delete])
            .launch();
    }
    else {
        eprintln!("Error: No database specified, make sure the DATABASE_URL env var is set.");
    };
}