Moved rocket API to a separate file
This commit is contained in:
parent
33ae1c07b2
commit
06c694ab4a
3 changed files with 25 additions and 24 deletions
23
src/api.rs
23
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<rocket::Route> {
|
||||
routes![version]
|
||||
}
|
||||
|
||||
pub fn get_handler(db: &Arc<DB>, index: &Arc<Mutex<Sender<index::Command>>>) -> Result<Chain> {
|
||||
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<Version> {
|
||||
let current_version = Version {
|
||||
major: CURRENT_MAJOR_VERSION,
|
||||
minor: CURRENT_MINOR_VERSION,
|
||||
};
|
||||
Json(current_version)
|
||||
}
|
||||
|
||||
fn initial_setup(_: &mut Request, db: &DB) -> IronResult<Response> {
|
||||
#[derive(Serialize)]
|
||||
struct InitialSetup {
|
||||
|
|
|
@ -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
|
||||
|
|
23
src/rocket_api.rs
Normal file
23
src/rocket_api.rs
Normal file
|
@ -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<rocket::Route> {
|
||||
routes![version]
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Version {
|
||||
major: i32,
|
||||
minor: i32,
|
||||
}
|
||||
|
||||
#[get("/version")]
|
||||
fn version() -> Json<Version> {
|
||||
let current_version = Version {
|
||||
major: CURRENT_MAJOR_VERSION,
|
||||
minor: CURRENT_MINOR_VERSION,
|
||||
};
|
||||
Json(current_version)
|
||||
}
|
Loading…
Add table
Reference in a new issue