blob: 84fe2398865ea0081c3c53c52567ec01789d59a7 (
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
|
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate diesel;
extern crate rocket;
#[macro_use] extern crate rocket_blog;
extern crate rocket_contrib;
#[macro_use] extern crate bart_derive;
#[macro_use] extern crate serde_derive;
use self::rocket_blog::{schema, models};
use rocket_contrib::Json;
mod posts;
#[derive(BartDisplay, Serialize)]
#[template = "templates/index.html"]
struct IndexTemplate<'a> {
title: &'a str,
posts: Vec<models::Post>
}
implement_responder_for!(IndexTemplate<'a>);
#[get("/", format = "text/html")]
fn index<'a>(conn: rocket_blog::DbConn) -> IndexTemplate<'a> {
IndexTemplate { title: "Bloggen", posts: models::get_posts(conn) }
}
#[get("/", format = "application/json")]
fn index_json(conn: rocket_blog::DbConn) -> Json<Vec<models::Post>> {
Json(models::get_posts(conn))
}
fn main() {
rocket::ignite()
.manage(rocket_blog::init_db_pool())
.mount("/", routes![index, index_json])
.mount("/posts", routes![posts::new, posts::create])
.launch();
}
|