From 06c694ab4a42eb16ec6e9a8b944e2146181230f3 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sat, 27 Oct 2018 15:24:52 -0700 Subject: [PATCH] Moved rocket API to a separate file --- src/api.rs | 23 ----------------------- src/main.rs | 3 ++- src/rocket_api.rs | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 src/rocket_api.rs diff --git a/src/api.rs b/src/api.rs index 0766847..6b0c7f4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -7,7 +7,6 @@ use iron::prelude::*; use iron::{status, AroundMiddleware, Handler}; use mount::Mount; use params; -use rocket_contrib::json::Json; use router::Router; use secure_session::middleware::{SessionConfig, SessionMiddleware}; use secure_session::session::ChaCha20Poly1305SessionManager; @@ -34,9 +33,6 @@ use user; use utils::*; use vfs::VFSSource; -const CURRENT_MAJOR_VERSION: i32 = 2; -const CURRENT_MINOR_VERSION: i32 = 2; - #[derive(Deserialize, Serialize)] struct Session { username: String, @@ -67,10 +63,6 @@ where Ok(secret) } -pub fn get_routes() -> Vec { - routes![version] -} - pub fn get_handler(db: &Arc, index: &Arc>>) -> Result { let api_handler = get_endpoints(&db.clone(), &index); let mut api_chain = Chain::new(api_handler); @@ -377,21 +369,6 @@ impl Handler for AdminHandler { } } -#[derive(Serialize)] -struct Version { - major: i32, - minor: i32, -} - -#[get("/version")] -fn version() -> Json { - let current_version = Version { - major: CURRENT_MAJOR_VERSION, - minor: CURRENT_MINOR_VERSION, - }; - Json(current_version) -} - fn initial_setup(_: &mut Request, db: &DB) -> IronResult { #[derive(Serialize)] struct InitialSetup { diff --git a/src/main.rs b/src/main.rs index 60f9357..ff2274d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,6 +75,7 @@ use std::sync::mpsc::channel; use std::sync::{Arc, Mutex}; mod api; +mod rocket_api; mod config; mod db; mod ddns; @@ -269,7 +270,7 @@ fn run() -> Result<()> { rocket::ignite() .mount(&static_url, StaticFiles::from(web_dir_path)) - .mount(&api_url, api::get_routes()) + .mount(&api_url, rocket_api::get_routes()) .launch(); // Start DDNS updates diff --git a/src/rocket_api.rs b/src/rocket_api.rs new file mode 100644 index 0000000..6febf90 --- /dev/null +++ b/src/rocket_api.rs @@ -0,0 +1,23 @@ +use rocket_contrib::json::Json; + +const CURRENT_MAJOR_VERSION: i32 = 2; +const CURRENT_MINOR_VERSION: i32 = 2; + +pub fn get_routes() -> Vec { + routes![version] +} + +#[derive(Serialize)] +struct Version { + major: i32, + minor: i32, +} + +#[get("/version")] +fn version() -> Json { + let current_version = Version { + major: CURRENT_MAJOR_VERSION, + minor: CURRENT_MINOR_VERSION, + }; + Json(current_version) +}