From 8801433784a54969897665719f037b19af580d1a Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 27 Jan 2019 18:37:49 -0600 Subject: [PATCH] Add actix app --- examples/resolver.rs | 11 +++-------- src/lib.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/examples/resolver.rs b/examples/resolver.rs index da58b65..242c373 100644 --- a/examples/resolver.rs +++ b/examples/resolver.rs @@ -1,5 +1,5 @@ -use actix_web::{server, App}; -use actix_webfinger::{Resolver, Webfinger, WebfingerPredicate}; +use actix_web::server; +use actix_webfinger::{Resolver, Webfinger}; use futures::{future::IntoFuture, Future}; #[derive(Clone, Debug)] @@ -29,14 +29,9 @@ impl Resolver for MyResolver { fn main() { server::new(|| { - App::with_state(MyState { + actix_webfinger::app::(MyState { domain: "asonix.dog".to_owned(), }) - .resource("/.well-known/webfinger", |r| { - r.route() - .filter(WebfingerPredicate) - .with(>::endpoint) - }) }) .bind("127.0.0.1:8000") .unwrap() diff --git a/src/lib.rs b/src/lib.rs index 6ed6a0b..e6fd78f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ use actix_web::{ error::ResponseError, http::Method, pred::Predicate, - HttpMessage, HttpResponse, Query, Request, State, + App, HttpMessage, HttpResponse, Query, Request, State, }; use failure::Fail; use futures::{future::IntoFuture, Future}; @@ -36,6 +36,16 @@ impl Predicate for WebfingerPredicate { } } +pub fn app(state: S) -> App +where + R: Resolver + 'static, + S: 'static, +{ + App::with_state(state).resource("/.well-known/webfinger", |r| { + r.route().filter(WebfingerPredicate).with(R::endpoint) + }) +} + #[derive(Clone, Debug, Fail)] #[fail(display = "Resource {} is invalid", _0)] pub struct InvalidResource(String);