this repo has no description
1use crate::state::AppState;
2use axum::{Json, extract::State, http::StatusCode, response::IntoResponse};
3use serde_json::json;
4
5use tracing::error;
6
7pub async fn robots_txt() -> impl IntoResponse {
8 (
9 StatusCode::OK,
10 [("content-type", "text/plain")],
11 "# Hello!\n\n# Crawling the public API is allowed\nUser-agent: *\nAllow: /\n",
12 )
13}
14
15pub async fn describe_server() -> impl IntoResponse {
16 let domains_str =
17 std::env::var("AVAILABLE_USER_DOMAINS").unwrap_or_else(|_| "example.com".to_string());
18 let domains: Vec<&str> = domains_str.split(',').map(|s| s.trim()).collect();
19
20 Json(json!({
21 "availableUserDomains": domains
22 }))
23}
24
25pub async fn health(State(state): State<AppState>) -> impl IntoResponse {
26 match sqlx::query!("SELECT 1 as one").fetch_one(&state.db).await {
27 Ok(_) => (StatusCode::OK, "OK"),
28 Err(e) => {
29 error!("Health check failed: {:?}", e);
30 (StatusCode::SERVICE_UNAVAILABLE, "Service Unavailable")
31 }
32 }
33}