use axum::Router; use jacquard_api::com_atproto::identity::resolve_did::ResolveDid; use jacquard_axum::ExtractXrpc; 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<'a, X: XrpcRequest<'a>> 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::post, })(handler), ) } } async fn handler(ExtractXrpc(args): ExtractXrpc>) -> &'static str { "hello world!" // let res = resolver::slingshot_resolver_default(); // let doc = res.resolve_did_doc(&args.did).await?; // let valid_doc = doc.parse()?; // let doc_value = serde_json::to_value(valid_doc).unwrap(); // Ok(ResolveDidOutput { // did_doc: Data::from_json(&doc_value).unwrap().into_static(), // extra_data: Default::default(), // } // .into()) } #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt() .with_timer(tracing_subscriber::fmt::time::UtcTime::rfc_3339()) .with_env_filter(EnvFilter::from_env("QDPDS_LOG")) .init(); let app = Router::new() .route("/", axum::routing::get(|| async { "hello world!" })) .merge(ResolveDid::into_router(handler)) .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(()) }