diff --git a/api/Cargo.lock b/api/Cargo.lock index 146e482..eca2534 100644 --- a/api/Cargo.lock +++ b/api/Cargo.lock @@ -1270,6 +1270,7 @@ dependencies = [ "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)", "rocket 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rocket-cache-response 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rocket_contrib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1547,6 +1548,14 @@ dependencies = [ "yansi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rocket-cache-response" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rocket 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rocket_codegen" version = "0.4.0" @@ -2529,6 +2538,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum reqwest 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0e60f169af3915c294818d55dde549f00d2966cef36d6c5e7255d75df3f2b16f" "checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a" "checksum rocket 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "242154377a85c2a9e036fc31ffc8c200b9e1f22a196e47baa3b57716606ca89d" +"checksum rocket-cache-response 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cabadf592a04d3d49cf1ebf02e4b755d4b57254dafdcbf10fcde2ee0a7ade36b" "checksum rocket_codegen 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d907d6d458c859651c1cf4c8fa99b77685082bde0561db6a4600b365058f710" "checksum rocket_contrib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f73e161dad5730435f51c815a5c6831d2e57b6b4299b1bf609d31b09aa9a2fa7" "checksum rocket_http 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba9d4f2ce5bba6e1b6d3100493bbad63879e99bbf6b4365d61e6f781daab324d" diff --git a/api/Cargo.toml b/api/Cargo.toml index 5304b68..dabb179 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -26,6 +26,7 @@ toml = "0.4" regex = "1.0" rocket = "0.4" rocket_contrib = "0.4" +rocket-cache-response = "0.5" url = "1.7" [dependencies.shiplift] diff --git a/api/src/main.rs b/api/src/main.rs index e4d1047..707a9cc 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -38,13 +38,11 @@ extern crate serde_derive; use crate::models::request_info::RequestInfo; use crate::services::config_service::Config; use rocket::response::NamedFile; +use rocket_cache_response::CacheResponse; use serde_yaml::{from_reader, to_string, Value}; -use shiplift::{ContainerListOptions, Docker}; use std::fs::File; use std::path::{Path, PathBuf}; use std::process; -use tokio::prelude::Future; -use tokio::runtime::Runtime; mod apps; mod commands; @@ -52,42 +50,22 @@ mod models; mod services; mod webhooks; -#[derive(Serialize)] -#[serde(rename_all = "camelCase")] -struct AppsStatus { - root_url: String, - swagger_ui_available: bool, - portainer_available: bool, -} - -fn is_container_available(container_image_pattern: &'static str) -> bool { - let future = Docker::new() - .containers() - .list(&ContainerListOptions::builder().build()) - .map(move |containers| { - containers - .iter() - .any(|c| c.image.starts_with(container_image_pattern)) - }); - - let mut runtime = Runtime::new().unwrap(); - match runtime.block_on(future) { - Err(e) => { - error!("Cannot list running containers: {}", e); - false - } - Ok(available) => available, - } -} - #[get("/")] -fn index() -> Option { - NamedFile::open(Path::new("frontend/index.html")).ok() +fn index() -> CacheResponse> { + CacheResponse::Public { + responder: NamedFile::open(Path::new("frontend/index.html")).ok(), + max_age: 60 * 60, // cached for seconds + must_revalidate: false, + } } #[get("/")] -fn files(path: PathBuf) -> Option { - NamedFile::open(Path::new("frontend/").join(path)).ok() +fn files(path: PathBuf) -> CacheResponse> { + CacheResponse::Public { + responder: NamedFile::open(Path::new("frontend/").join(path)).ok(), + max_age: 60 * 60, // cached for seconds + must_revalidate: false, + } } #[get("/")]