web/src/relay.rs

50 lines
1.7 KiB
Rust
Raw Normal View History

2023-10-16 01:36:01 +02:00
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())
}
2023-10-16 01:36:02 +02:00
#[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())
}
2023-10-16 01:36:02 +02:00
#[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)
2023-10-16 01:36:02 +02:00
.service(get_hub_issues)
2023-10-16 01:36:02 +02:00
.service(get_hub_issue_timeline)
);
}