fix(examples): use axum::serve
This commit is contained in:
parent
4d7ebc3493
commit
1b1b4e9ff1
4 changed files with 23 additions and 25 deletions
|
|
@ -12,10 +12,8 @@ use axum::{
|
|||
Router,
|
||||
};
|
||||
use error::Error;
|
||||
use std::{
|
||||
net::ToSocketAddrs,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::net::TcpListener;
|
||||
use tracing::log::{info, LevelFilter};
|
||||
|
||||
mod activities;
|
||||
|
|
@ -60,13 +58,13 @@ async fn main() -> Result<(), Error> {
|
|||
.route("/.well-known/webfinger", get(webfinger))
|
||||
.layer(FederationMiddleware::new(config));
|
||||
|
||||
let addr = BIND_ADDRESS
|
||||
.to_socket_addrs()?
|
||||
.next()
|
||||
.expect("Failed to lookup domain name");
|
||||
axum::Server::bind(&addr)
|
||||
.serve(app.into_make_service())
|
||||
.await?;
|
||||
axum::serve(
|
||||
TcpListener::bind(BIND_ADDRESS)
|
||||
.await
|
||||
.expect("Failed to lookup domain name"),
|
||||
app.into_make_service(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,14 @@ use axum::{
|
|||
extract::{Path, Query},
|
||||
response::IntoResponse,
|
||||
routing::{get, post},
|
||||
Json,
|
||||
Router,
|
||||
Json, Router,
|
||||
};
|
||||
use axum_macros::debug_handler;
|
||||
use serde::Deserialize;
|
||||
use std::net::ToSocketAddrs;
|
||||
use tokio::net::TcpListener;
|
||||
use tracing::info;
|
||||
|
||||
pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
|
||||
pub async fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
|
||||
let hostname = config.domain();
|
||||
info!("Listening with axum on {hostname}");
|
||||
let config = config.clone();
|
||||
|
|
@ -35,13 +34,14 @@ pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
|
|||
.route("/.well-known/webfinger", get(webfinger))
|
||||
.layer(FederationMiddleware::new(config));
|
||||
|
||||
let addr = hostname
|
||||
.to_socket_addrs()?
|
||||
.next()
|
||||
.expect("Failed to lookup domain name");
|
||||
let server = axum::Server::bind(&addr).serve(app.into_make_service());
|
||||
axum::serve(
|
||||
TcpListener::bind(hostname)
|
||||
.await
|
||||
.expect("Failed to lookup domain name"),
|
||||
app.into_make_service(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
tokio::spawn(server);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,12 +76,12 @@ impl FromStr for Webserver {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn listen(
|
||||
pub async fn listen(
|
||||
config: &FederationConfig<DatabaseHandle>,
|
||||
webserver: &Webserver,
|
||||
) -> Result<(), Error> {
|
||||
match webserver {
|
||||
Webserver::Axum => crate::axum::http::listen(config)?,
|
||||
Webserver::Axum => crate::axum::http::listen(config).await?,
|
||||
// Webserver::ActixWeb => crate::actix_web::http::listen(config)?,
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ async fn main() -> Result<(), Error> {
|
|||
|
||||
let alpha = new_instance("localhost:8001", "alpha".to_string()).await?;
|
||||
let beta = new_instance("localhost:8002", "beta".to_string()).await?;
|
||||
listen(&alpha, &webserver)?;
|
||||
listen(&beta, &webserver)?;
|
||||
listen(&alpha, &webserver).await?;
|
||||
listen(&beta, &webserver).await?;
|
||||
info!("Local instances started");
|
||||
|
||||
info!("Alpha user follows beta user via webfinger");
|
||||
|
|
|
|||
Loading…
Reference in a new issue