Add actix app
This commit is contained in:
parent
d017443d81
commit
8801433784
|
@ -1,5 +1,5 @@
|
||||||
use actix_web::{server, App};
|
use actix_web::server;
|
||||||
use actix_webfinger::{Resolver, Webfinger, WebfingerPredicate};
|
use actix_webfinger::{Resolver, Webfinger};
|
||||||
use futures::{future::IntoFuture, Future};
|
use futures::{future::IntoFuture, Future};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -29,14 +29,9 @@ impl Resolver<MyState> for MyResolver {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
server::new(|| {
|
server::new(|| {
|
||||||
App::with_state(MyState {
|
actix_webfinger::app::<MyState, MyResolver>(MyState {
|
||||||
domain: "asonix.dog".to_owned(),
|
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")
|
.bind("127.0.0.1:8000")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -4,7 +4,7 @@ use actix_web::{
|
||||||
error::ResponseError,
|
error::ResponseError,
|
||||||
http::Method,
|
http::Method,
|
||||||
pred::Predicate,
|
pred::Predicate,
|
||||||
HttpMessage, HttpResponse, Query, Request, State,
|
App, HttpMessage, HttpResponse, Query, Request, State,
|
||||||
};
|
};
|
||||||
use failure::Fail;
|
use failure::Fail;
|
||||||
use futures::{future::IntoFuture, Future};
|
use futures::{future::IntoFuture, Future};
|
||||||
|
@ -36,6 +36,16 @@ impl<S> Predicate<S> for WebfingerPredicate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn app<S, R>(state: S) -> App<S>
|
||||||
|
where
|
||||||
|
R: Resolver<S> + 'static,
|
||||||
|
S: 'static,
|
||||||
|
{
|
||||||
|
App::with_state(state).resource("/.well-known/webfinger", |r| {
|
||||||
|
r.route().filter(WebfingerPredicate).with(R::endpoint)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Fail)]
|
#[derive(Clone, Debug, Fail)]
|
||||||
#[fail(display = "Resource {} is invalid", _0)]
|
#[fail(display = "Resource {} is invalid", _0)]
|
||||||
pub struct InvalidResource(String);
|
pub struct InvalidResource(String);
|
||||||
|
|
Loading…
Reference in a new issue