fail.rs
65 lines 2.3 kB view raw
1use axum::Router; 2use jacquard_api::com_atproto::identity::resolve_did::ResolveDid; 3use jacquard_axum::ExtractXrpc; 4use jacquard_common::types::xrpc::{XrpcMethod, XrpcRequest}; 5use miette::{IntoDiagnostic, Result}; 6use tracing_subscriber::EnvFilter; 7 8trait IntoRouter { 9 fn into_router<T, S, U>(handler: U) -> Router<S> 10 where 11 T: 'static, 12 S: Clone + Send + Sync + 'static, 13 U: axum::handler::Handler<T, S>; 14} 15 16impl<'a, X: XrpcRequest<'a>> IntoRouter for X { 17 /// Creates an axum router that will invoke `handler` in response to xrpc 18 /// request `X`. 19 fn into_router<T, S, U>(handler: U) -> Router<S> 20 where 21 T: 'static, 22 S: Clone + Send + Sync + 'static, 23 U: axum::handler::Handler<T, S>, 24 { 25 Router::new().route( 26 // this should really be a compile time operation, but I cannot 27 // figure out how to make that happen 28 format!("/xrpc/{}", X::NSID).as_str(), 29 (match X::METHOD { 30 XrpcMethod::Query => axum::routing::get, 31 XrpcMethod::Procedure(_) => axum::routing::post, 32 })(handler), 33 ) 34 } 35} 36 37async fn handler(ExtractXrpc(args): ExtractXrpc<ResolveDid<'static>>) -> &'static str { 38 "hello world!" 39 // let res = resolver::slingshot_resolver_default(); 40 // let doc = res.resolve_did_doc(&args.did).await?; 41 // let valid_doc = doc.parse()?; 42 // let doc_value = serde_json::to_value(valid_doc).unwrap(); 43 // Ok(ResolveDidOutput { 44 // did_doc: Data::from_json(&doc_value).unwrap().into_static(), 45 // extra_data: Default::default(), 46 // } 47 // .into()) 48} 49 50#[tokio::main] 51async fn main() -> Result<()> { 52 tracing_subscriber::fmt() 53 .with_timer(tracing_subscriber::fmt::time::UtcTime::rfc_3339()) 54 .with_env_filter(EnvFilter::from_env("QDPDS_LOG")) 55 .init(); 56 let app = Router::new() 57 .route("/", axum::routing::get(|| async { "hello world!" })) 58 .merge(ResolveDid::into_router(handler)) 59 .layer(tower_http::trace::TraceLayer::new_for_http()); 60 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000") 61 .await 62 .into_diagnostic()?; 63 axum::serve(listener, app).await.unwrap(); 64 Ok(()) 65}