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