actix-webfinger/examples/resolver.rs
2019-01-27 18:29:01 -06:00

45 lines
1 KiB
Rust

use actix_web::{server, App};
use actix_webfinger::{Resolver, Webfinger, WebfingerPredicate};
use futures::{future::IntoFuture, Future};
#[derive(Clone, Debug)]
pub struct MyState {
domain: String,
}
pub struct MyResolver;
impl Resolver<MyState> for MyResolver {
type Error = actix_web::error::JsonPayloadError;
fn find(
account: &str,
domain: &str,
state: &MyState,
) -> Box<dyn Future<Item = Option<Webfinger>, Error = Self::Error>> {
let w = if domain == state.domain {
Some(Webfinger::new(&format!("{}@{}", account, domain)))
} else {
None
};
Box::new(Ok(w).into_future())
}
}
fn main() {
server::new(|| {
App::with_state(MyState {
domain: "asonix.dog".to_owned(),
})
.resource("/.well-known/webfinger", |r| {
r.route()
.filter(WebfingerPredicate)
.with(<MyResolver as Resolver<MyState>>::endpoint)
})
})
.bind("127.0.0.1:8000")
.unwrap()
.run();
}