web/src/relay.rs

50 lines
No EOL
1.7 KiB
Rust

use actix_web::{get, HttpResponse, web};
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())
}
#[get("/hub_issues")]
pub async fn get_hub_issues() -> HttpResponse {
let status_response = if let Ok(res) = reqwest::get("https://git.ixvd.net/api/v1/repos/ixvd/hub/issues?state=open").await {
res
} else {
return HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR)
.body("Failed to get status from forgejo");
};
HttpResponse::build(StatusCode::OK)
.body(status_response.text().await.unwrap())
}
#[get("/hub_issue_timeline/{issue_id}")]
pub async fn get_hub_issue_timeline(info: web::Path<(u32,)>) -> HttpResponse {
let status_response = if let Ok(res) = reqwest::get(format!("https://git.ixvd.net/api/v1/repos/ixvd/hub/issues/{}/timeline", info.into_inner().0)).await {
res
} else {
return HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR)
.body("Failed to get status from forgejo");
};
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)
.service(get_hub_issues)
.service(get_hub_issue_timeline)
);
}