forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.rs
More file actions
43 lines (34 loc) · 1.26 KB
/
server.rs
File metadata and controls
43 lines (34 loc) · 1.26 KB
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
use std::net::SocketAddr;
use std::sync::Arc;
use axum_server::tls_rustls::RustlsConfig;
use axum_server::Handle;
use futures::Future;
use log::info;
use warp::hyper;
use super::routes::router;
use crate::tracker::Tracker;
pub fn start(socket_addr: SocketAddr, tracker: &Arc<Tracker>) -> impl Future<Output = hyper::Result<()>> {
let app = router(tracker);
let server = axum::Server::bind(&socket_addr).serve(app.into_make_service());
server.with_graceful_shutdown(async move {
tokio::signal::ctrl_c().await.expect("Failed to listen to shutdown signal.");
info!("Stopping Torrust APIs server on http://{} ...", socket_addr);
})
}
pub fn start_tls(
socket_addr: SocketAddr,
ssl_config: RustlsConfig,
tracker: &Arc<Tracker>,
) -> impl Future<Output = Result<(), std::io::Error>> {
let app = router(tracker);
let handle = Handle::new();
let shutdown_handle = handle.clone();
tokio::spawn(async move {
tokio::signal::ctrl_c().await.expect("Failed to listen to shutdown signal.");
info!("Stopping Torrust APIs server on https://{} ...", socket_addr);
shutdown_handle.shutdown();
});
axum_server::bind_rustls(socket_addr, ssl_config)
.handle(handle)
.serve(app.into_make_service())
}