add umbrella crate

This commit is contained in:
Aleksandr 2025-09-20 22:55:40 +03:00
parent d171fc723b
commit fe04530f84
17 changed files with 247 additions and 5 deletions

View file

@ -1,10 +1,13 @@
use eva::perfect_derive;
use eva::{perfect_derive, supervisor::SlaveRx};
use eyre::Context;
use viendesu_core::{
errors::AuxResult,
service::{Service, SessionMaker, SessionOf},
};
use tokio::net;
pub mod config;
mod context;
@ -18,6 +21,31 @@ pub trait Types: Send + Sync + 'static {
type Service: Service + Clone;
}
pub async fn serve(
rx: SlaveRx,
config: config::Config,
router: axum::Router,
) -> eyre::Result<()> {
// TODO: use it.
_ = rx;
let config::Config { unencrypted, ssl: _ } = config;
let unencrypted = unencrypted.expect("SSL-only currently is not supported");
if !unencrypted.enable {
return Ok(());
}
let listener = net::TcpListener::bind(unencrypted.listen)
.await
.wrap_err("failed to bind address")?;
axum::serve(listener, router)
.await
.wrap_err("failed to serve")?;
Ok(())
}
pub fn make_router<T: Types>(service: T::Service) -> axum::Router {
let scope = handler::RouterScope::root(State::<T> { service });
routes::make(scope).into_axum()