diff --git a/Cargo.toml b/Cargo.toml index 7b9e8f4..acff525 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ categories = ["command-line-utilities"] readme = "README.md" license = "MIT" edition = "2021" -include = ["/src", "build.rs", "LICENSE"] +include = ["/src", "build.rs", "LICENSE", "stdlib/"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -21,6 +21,7 @@ path = "src/main.rs" base64 = "0.21.0" clap = { version = "4.2.7", features = ["derive"] } jsonwebtoken = "8.3.0" +rand = "0.8.5" rocket = { version = "0.5.0-rc.3", features = ["json"] } sha256 = "1.1.3" shadow-rs = "0.21.0" diff --git a/src/server.rs b/src/server.rs index a797176..f8b635a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,10 +1,12 @@ use std::net::Ipv4Addr; use std::path::PathBuf; +use rocket::serde::{json::Json, Deserialize, Serialize}; use rocket::Build; use rocket::Config; use rocket::Rocket; +use crate::cli::build; use crate::compile; use crate::jwt; use crate::system; @@ -14,11 +16,34 @@ fn index() -> &'static str { "I am Compilet." } +#[derive(Debug, Serialize, Deserialize)] +#[serde(crate = "rocket::serde")] +pub struct ServerInfo { + pub version: String, + pub commit: String, + pub build_time: String, + pub os: String, +} + +#[get("/info")] +fn info() -> Json { + Json(ServerInfo { + version: build::PKG_VERSION.to_string(), + commit: build::COMMIT_HASH.to_string(), + build_time: build::BUILD_TIME.to_string(), + os: build::BUILD_OS.to_string(), + }) +} + /// Get the Rocket instance pub fn rocket() -> Rocket { rocket::build() .configure(Config { address: Ipv4Addr::new(0, 0, 0, 0).into(), + port: std::env::var("PORT") + .unwrap_or_else(|_| "32000".to_string()) + .parse() + .unwrap(), ..Config::default() }) .manage(compile::WasmCache { @@ -26,6 +51,6 @@ pub fn rocket() -> Rocket { }) .mount( "/", - routes![index, system::system, compile::compile, jwt::validate], + routes![index, info, system::system, compile::compile, jwt::validate], ) }