Extract make_router from serve

Signed-off-by: Olivier 'reivilibre <olivier@librepush.net>
This commit is contained in:
Olivier 'reivilibre' 2024-07-04 23:36:39 +01:00
parent 8ddb2c7f0a
commit ed9a36a662

View File

@ -55,14 +55,13 @@ make_template_manager! {
};
}
/// Serves, on the bind address specified, the HTTP service
/// including a user interface and any OAuth, OpenID Connect and custom APIs.
pub async fn serve(
bind: SocketAddr,
/// Make an axum `Router` but do not bind it to a port.
/// This exposition allows us to perform integration testing easily.
pub(crate) async fn make_router(
store: Arc<IdCoopStore>,
config: Arc<Configuration>,
secrets: Arc<SecretConfig>,
) -> eyre::Result<()> {
) -> eyre::Result<Router> {
initialise_template_manager!(TEMPLATING);
let client_ip_source = config.listen.client_ip_source.clone();
@ -126,6 +125,19 @@ pub async fn serve(
.layer(Extension(Arc::new(ratelimiters)))
.layer(Extension(VolatileCodeStore::default()));
Ok(router)
}
/// Serves, on the bind address specified, the HTTP service
/// including a user interface and any OAuth, OpenID Connect and custom APIs.
pub async fn serve(
bind: SocketAddr,
store: Arc<IdCoopStore>,
config: Arc<Configuration>,
secrets: Arc<SecretConfig>,
) -> eyre::Result<()> {
let router = make_router(store, config, secrets).await?;
info!("Listening on {bind:?}");
axum::Server::try_bind(&bind)
.context("could not bind listen address")?
@ -213,7 +225,7 @@ impl Ratelimiters {
/// Do some housekeeping if it hasn't been done recently.
pub fn housekeeping(&self) {
let Ok(now) = SystemTime::now().duration_since(UNIX_EPOCH) else {
return
return;
};
let now = (now.as_secs() >> 2) as u32;