-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
46 lines (37 loc) · 1012 Bytes
/
main.rs
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
46
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
extern crate serde_json;
#[macro_use] extern crate rocket_contrib;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate mysql;
use rocket::{Rocket};
use rocket_contrib::{JSON, Value};
mod superstar;
mod talent;
#[error(404)]
fn not_found() -> JSON<Value> {
JSON(json!({
"status": "error",
"reason": "Resource was not found."
}))
}
fn rocket() -> Rocket {
let mut opts = mysql::OptsBuilder::new();
opts.db_name(Some("pwfantasy"));
opts.prefer_socket(false); // only set to "false" when on windows
opts.user(Some(env!("PWFDB_USER")));
opts.pass(Some(env!("PWFDB_PASS")));
let pool = mysql::Pool::new(opts).unwrap();
rocket::ignite()
.manage(pool)
.mount("/superstar", routes![
superstar::upsert,
superstar::retrieve,
superstar::search,
])
.catch(errors![not_found])
}
fn main() {
rocket().launch();
}