add umbrella crate
This commit is contained in:
parent
d171fc723b
commit
fe04530f84
17 changed files with 247 additions and 5 deletions
|
@ -4,13 +4,15 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ["client", "server"]
|
||||
client = ["dep:reqwest"]
|
||||
server = [
|
||||
"dep:axum",
|
||||
"dep:http-body-util",
|
||||
"dep:tower-http",
|
||||
"dep:serde_urlencoded",
|
||||
"eva/tokio",
|
||||
"tokio/net"
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
|
@ -30,4 +32,6 @@ http-body-util = { version = "0.1.3", optional = true }
|
|||
tower-http = { optional = true, version = "0.6.6", default-features = false, features = ["limit"] }
|
||||
serde_urlencoded = { version = "0.7.1", optional = true }
|
||||
|
||||
tokio = { workspace = true, optional = true }
|
||||
|
||||
reqwest = { optional = true, version = "0.12.23", default-features = false }
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -52,8 +52,8 @@ pub fn ok<O: IsResponse>(format: Format, ok: O) -> AxumResponse {
|
|||
pub fn respond<O: IsResponse>(format: Format, res: O) -> AxumResponse {
|
||||
let status_code = res.status_code();
|
||||
let headers = [
|
||||
header!("Server" => "Kurisu-desu"),
|
||||
header!("Content-Type" => format.mime_type()),
|
||||
header!("server" => "Kurisu-desu"),
|
||||
header!("content-type" => format.mime_type()),
|
||||
];
|
||||
|
||||
let mut body = Vec::with_capacity(128);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue