Ported version endpoint to rocket
This commit is contained in:
parent
43894d71f7
commit
33ae1c07b2
4 changed files with 17 additions and 13 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1839,6 +1839,8 @@ dependencies = [
|
||||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"notify 4.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"notify 4.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rocket 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket.git?rev=556206e)",
|
"rocket 0.4.0-dev (git+https://github.com/SergioBenitez/Rocket.git?rev=556206e)",
|
||||||
|
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -55,7 +55,7 @@ rev = "556206e"
|
||||||
[dependencies.rocket_contrib]
|
[dependencies.rocket_contrib]
|
||||||
version = "0.4.0-dev"
|
version = "0.4.0-dev"
|
||||||
default_features = false
|
default_features = false
|
||||||
features = ["serve"]
|
features = ["json", "serve"]
|
||||||
|
|
||||||
[dependencies.rusqlite]
|
[dependencies.rusqlite]
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
|
|
25
src/api.rs
25
src/api.rs
|
@ -7,6 +7,7 @@ use iron::prelude::*;
|
||||||
use iron::{status, AroundMiddleware, Handler};
|
use iron::{status, AroundMiddleware, Handler};
|
||||||
use mount::Mount;
|
use mount::Mount;
|
||||||
use params;
|
use params;
|
||||||
|
use rocket_contrib::json::Json;
|
||||||
use router::Router;
|
use router::Router;
|
||||||
use secure_session::middleware::{SessionConfig, SessionMiddleware};
|
use secure_session::middleware::{SessionConfig, SessionMiddleware};
|
||||||
use secure_session::session::ChaCha20Poly1305SessionManager;
|
use secure_session::session::ChaCha20Poly1305SessionManager;
|
||||||
|
@ -66,6 +67,10 @@ where
|
||||||
Ok(secret)
|
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> {
|
pub fn get_handler(db: &Arc<DB>, index: &Arc<Mutex<Sender<index::Command>>>) -> Result<Chain> {
|
||||||
let api_handler = get_endpoints(&db.clone(), &index);
|
let api_handler = get_endpoints(&db.clone(), &index);
|
||||||
let mut api_chain = Chain::new(api_handler);
|
let mut api_chain = Chain::new(api_handler);
|
||||||
|
@ -87,7 +92,6 @@ fn get_endpoints(db: &Arc<DB>, index_channel: &Arc<Mutex<Sender<index::Command>>
|
||||||
let mut api_handler = Mount::new();
|
let mut api_handler = Mount::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
api_handler.mount("/version/", self::version);
|
|
||||||
{
|
{
|
||||||
let db = db.clone();
|
let db = db.clone();
|
||||||
api_handler.mount("/auth/", move |request: &mut Request| {
|
api_handler.mount("/auth/", move |request: &mut Request| {
|
||||||
|
@ -373,22 +377,19 @@ impl Handler for AdminHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version(_: &mut Request) -> IronResult<Response> {
|
#[derive(Serialize)]
|
||||||
#[derive(Serialize)]
|
struct Version {
|
||||||
struct Version {
|
major: i32,
|
||||||
major: i32,
|
minor: i32,
|
||||||
minor: i32,
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
#[get("/version")]
|
||||||
|
fn version() -> Json<Version> {
|
||||||
let current_version = Version {
|
let current_version = Version {
|
||||||
major: CURRENT_MAJOR_VERSION,
|
major: CURRENT_MAJOR_VERSION,
|
||||||
minor: CURRENT_MINOR_VERSION,
|
minor: CURRENT_MINOR_VERSION,
|
||||||
};
|
};
|
||||||
|
Json(current_version)
|
||||||
match serde_json::to_string(¤t_version) {
|
|
||||||
Ok(result_json) => Ok(Response::with((status::Ok, result_json))),
|
|
||||||
Err(e) => Err(IronError::new(e, status::InternalServerError)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initial_setup(_: &mut Request, db: &DB) -> IronResult<Response> {
|
fn initial_setup(_: &mut Request, db: &DB) -> IronResult<Response> {
|
||||||
|
|
|
@ -269,6 +269,7 @@ fn run() -> Result<()> {
|
||||||
|
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.mount(&static_url, StaticFiles::from(web_dir_path))
|
.mount(&static_url, StaticFiles::from(web_dir_path))
|
||||||
|
.mount(&api_url, api::get_routes())
|
||||||
.launch();
|
.launch();
|
||||||
|
|
||||||
// Start DDNS updates
|
// Start DDNS updates
|
||||||
|
|
Loading…
Add table
Reference in a new issue