Created
October 24, 2019 11:41
-
-
Save louis030195/f39047d87c219a8c9afe552f4b84136c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(decl_macro, proc_macro_hygiene)] | |
#[macro_use] | |
extern crate rocket; | |
extern crate dotenv; | |
extern crate mongodb; | |
extern crate r2d2; | |
extern crate r2d2_mongodb; | |
extern crate rocket_contrib; | |
#[macro_use] | |
extern crate serde_derive; | |
extern crate serde_json; | |
use dotenv::dotenv; | |
use rocket::{Request, Rocket}; | |
pub mod cats; | |
mod mongo_connection; | |
#[catch(500)] | |
fn internal_error() -> &'static str { | |
"Whoops! Looks like we messed up." | |
} | |
#[catch(400)] | |
fn not_found(req: &Request) -> String { | |
format!("I couldn't find '{}'. Try something else?", req.uri()) | |
} | |
pub fn rocket() -> Rocket { | |
dotenv().ok(); | |
rocket::ignite() | |
.register(catchers![internal_error, not_found]) | |
.manage(mongo_connection::init_pool()) | |
.mount( | |
"/cats", | |
routes![ | |
cats::handler::all, | |
cats::handler::get, | |
cats::handler::post, | |
cats::handler::put, | |
cats::handler::delete, | |
cats::handler::delete_all | |
], | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment