-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.rs
57 lines (49 loc) · 1.54 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
mod configuration;
mod error;
mod namespace;
mod resp;
mod service;
use async_trait::async_trait;
use salvo::prelude::TcpListener;
use salvo::serve_static::StaticDir;
use salvo::{Depot, FlowCtrl, Handler, Request, Response, Router, Server};
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::data::LuoshuSledData;
use configuration::get_routers as get_configuration_routers;
use namespace::get_routers as get_namespace_routers;
use service::get_routers as get_service_routers;
/// Web管理层执行器
pub async fn run_server(addr: &str, data: Arc<RwLock<LuoshuSledData>>) {
let set_store = SetStore(data);
let router = Router::with_hoop(set_store)
.push(
Router::with_path("api")
.push(get_service_routers())
.push(get_namespace_routers())
.push(get_configuration_routers()),
)
.push(
Router::with_path("<**path>").get(
StaticDir::new(["luoshu-frontend/dist"])
.with_defaults("index.html")
.with_listing(true),
),
);
tracing::info!("admin listening on: http://{}", addr);
Server::new(TcpListener::bind(addr)).serve(router).await;
}
struct SetStore(Arc<RwLock<LuoshuSledData>>);
#[async_trait]
impl Handler for SetStore {
async fn handle(
&self,
_req: &mut Request,
_depot: &mut Depot,
_res: &mut Response,
_ctrl: &mut FlowCtrl,
) {
_depot.inject(self.0.clone());
_ctrl.call_next(_req, _depot, _res).await;
}
}