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