use axum::Router; use axum::extract::Query; use jacquard_api::com_atproto::identity::resolve_did::ResolveDid; use jacquard_common::types::xrpc::{XrpcMethod, XrpcRequest}; use miette::{IntoDiagnostic, Result}; use tracing_subscriber::EnvFilter; trait IntoRouter { fn into_router(handler: U) -> Router where T: 'static, S: Clone + Send + Sync + 'static, U: axum::handler::Handler; } impl IntoRouter for X { /// Creates an axum router that will invoke `handler` in response to xrpc /// request `X`. fn into_router(handler: U) -> Router where T: 'static, S: Clone + Send + Sync + 'static, U: axum::handler::Handler, { Router::new().route( // this should really be a compile time operation, but I cannot // figure out how to make that happen format!("/xrpc/{}", X::NSID).as_str(), (match X::METHOD { XrpcMethod::Query => axum::routing::get, XrpcMethod::Procedure(_) => axum::routing::put, })(handler), ) } } #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt() .with_timer(tracing_subscriber::fmt::time::UtcTime::rfc_3339()) .with_env_filter(EnvFilter::from_env("QPDS_LOG")) .init(); let app = Router::new() .route("/", axum::routing::get(|| async { "hello world!" })) .merge(ResolveDid::into_router( |Query(args): Query| async { "DID resolver goes here eventually!" }, )) .layer(tower_http::trace::TraceLayer::new_for_http()); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000") .await .into_diagnostic()?; axum::serve(listener, app).await.unwrap(); Ok(()) }