mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-09 02:47:45 +08:00
refactor: 拆分 gateway 单体为独立 crate,新增 systemd 部署方案
将 gateway 内部的 model-fetch、provider-transport、scheduler-core、 usage-runtime、video-tasks-core 模块提取为独立 crate;重构 gateway 内部模块结构(state/router/cache/data/query 等);移除大量遗留模块 文件;新增 systemd 二进制部署骨架及相关文档;更新前端 usage 相关 API 和组件。
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
use axum::routing::any;
|
||||
use axum::Router;
|
||||
|
||||
use aether_runtime::{prometheus_response, ConcurrencyError, DistributedConcurrencyError};
|
||||
|
||||
use super::{api, handlers::proxy::proxy_request, middleware, state::AppState};
|
||||
|
||||
pub fn build_router() -> Result<Router, reqwest::Error> {
|
||||
Ok(build_router_with_state(AppState::new()?))
|
||||
}
|
||||
|
||||
pub fn build_router_with_state(state: AppState) -> Router {
|
||||
let cors_state = state.clone();
|
||||
let mut router = Router::<AppState>::new();
|
||||
router = api::mount_core_routes(router);
|
||||
router = api::mount_operational_routes(router);
|
||||
router = api::mount_ai_routes(router);
|
||||
router = api::mount_public_support_routes(router);
|
||||
router = api::mount_oauth_routes(router);
|
||||
router = api::mount_internal_routes(router);
|
||||
router = api::mount_admin_routes(router);
|
||||
let mut router = router
|
||||
.route("/{*path}", any(proxy_request))
|
||||
.layer(axum::middleware::from_fn(middleware::access_log_middleware))
|
||||
.with_state(state);
|
||||
if cors_state.frontdoor_cors().is_some() {
|
||||
router = router.layer(axum::middleware::from_fn_with_state(
|
||||
cors_state,
|
||||
middleware::frontdoor_cors_middleware,
|
||||
));
|
||||
}
|
||||
router
|
||||
}
|
||||
|
||||
pub(crate) async fn metrics(
|
||||
axum::extract::State(state): axum::extract::State<AppState>,
|
||||
) -> impl axum::response::IntoResponse {
|
||||
prometheus_response(&state.metric_samples().await)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum RequestAdmissionError {
|
||||
Local(ConcurrencyError),
|
||||
Distributed(DistributedConcurrencyError),
|
||||
}
|
||||
|
||||
pub async fn serve_tcp(bind: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let listener = tokio::net::TcpListener::bind(bind).await?;
|
||||
let router = build_router()?;
|
||||
axum::serve(
|
||||
listener,
|
||||
router.into_make_service_with_connect_info::<std::net::SocketAddr>(),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user