aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-10 15:50:51 -0700
committerFuwn <[email protected]>2021-05-10 15:55:30 -0700
commitc9e1bc37faf2e4d15bf9a9aa18a5f483d9235518 (patch)
tree7cc25b93f1a46f3bd4da1b1ae650c217f9c403b7 /src/api/routes
parentMerge pull request #16 from Whirlsplash/renovate/commitizen-4.x (diff)
downloadwhirl-c9e1bc37faf2e4d15bf9a9aa18a5f483d9235518.tar.xz
whirl-c9e1bc37faf2e4d15bf9a9aa18a5f483d9235518.zip
perf(api): use actix_web instead of rocket for api
Refactors API for Actix, also enables CORS. BREAKING CHANGE: `whirlsplash.port.api` configuration key created. closes #20
Diffstat (limited to 'src/api/routes')
-rw-r--r--src/api/routes/mod.rs3
-rw-r--r--src/api/routes/stats/mod.rs11
2 files changed, 5 insertions, 9 deletions
diff --git a/src/api/routes/mod.rs b/src/api/routes/mod.rs
index 231236c..f5a2ff4 100644
--- a/src/api/routes/mod.rs
+++ b/src/api/routes/mod.rs
@@ -2,6 +2,3 @@
// SPDX-License-Identifier: GPL-3.0-only
pub mod stats;
-
-#[get("/")]
-pub fn index() -> &'static str { "Whirlsplash" }
diff --git a/src/api/routes/stats/mod.rs b/src/api/routes/stats/mod.rs
index f7af6e8..04ce5e6 100644
--- a/src/api/routes/stats/mod.rs
+++ b/src/api/routes/stats/mod.rs
@@ -3,7 +3,7 @@
pub mod structures;
-use rocket_contrib::json::Json;
+use actix_web::HttpResponse;
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
use crate::{
@@ -13,24 +13,23 @@ use crate::{
// This is mostly for developmental testing, it consumes more CPU than it's
// worth.
-#[get("/statistics")]
-pub fn statistics() -> Json<Statistics> {
+pub fn statistics() -> HttpResponse {
let mut sys = System::new_all();
sys.refresh_all();
let process = sys.get_process(get_current_pid().unwrap()).unwrap();
- Json(Statistics {
+ HttpResponse::Ok().json(Statistics {
system: StatisticsSystem {
os_type: sys.get_name().unwrap(),
release: sys.get_kernel_version().unwrap(),
uptime: seconds_to_hrtime(sysinfo::System::new().get_uptime() as usize),
},
process: StatisticsProcess {
- memory_usage: (process.memory() / 1000).to_string(),
// (process.cpu_usage() * 100.0).round() / 100.0
+ memory_usage: (process.memory() / 1000).to_string(),
cpu_usage: (process.cpu_usage() / sys.get_processors().len() as f32).to_string(),
- // uptime: seconds_to_hrtime((sys.get_uptime() - process.start_time()) as usize),
+ // uptime: seconds_to_hrtime((sys.get_uptime() - process.start_time()) as usize),
},
})
}