feat: added a relay for gatus statuses and changes the url it uses

This commit is contained in:
Strix 2023-10-16 01:36:01 +02:00
parent 39134b5229
commit 43d05fadc4
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
8 changed files with 1910 additions and 4 deletions

23
src/main.rs Normal file
View file

@ -0,0 +1,23 @@
use actix_files as fs;
use actix_web::{App, HttpServer, middleware};
use env_logger;
mod relay;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
HttpServer::new(|| {
App::new()
.wrap(middleware::Logger::default())
.configure(relay::configure)
.service(
fs::Files::new("/", "./public/")
.index_file("index.html")
)
})
.bind(("0.0.0.0", 8080))?
.run()
.await
}

22
src/relay.rs Normal file
View file

@ -0,0 +1,22 @@
use actix_web::{HttpResponse, web, get};
use actix_web::http::StatusCode;
#[get("/gatus")]
pub async fn get_gatus_services() -> HttpResponse {
let status_response = if let Ok(res) = reqwest::get("https://s.ixvd.net/api/v1/endpoints/statuses").await {
res
} else {
return HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR)
.body("Failed to get status from gatus");
};
HttpResponse::build(StatusCode::OK)
.body(status_response.text().await.unwrap())
}
pub fn configure(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/relay")
.service(get_gatus_services)
);
}