feat: add the hot-reload on backend crate

This commit is contained in:
2024-09-23 18:13:48 +02:00
parent a50d951af7
commit 54870b0d0f
5 changed files with 1397 additions and 47 deletions

View File

@ -1,9 +1,23 @@
use listenfd::ListenFd;
use tokio::net::TcpListener;
use backend::get_router;
#[tokio::main]
async fn main() {
let app = get_router();
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
let mut listenfd = ListenFd::from_env();
let listener = match listenfd.take_tcp_listener(0).unwrap() {
// if we are given a tcp listener on listen fd 0, we use that one
Some(listener) => {
listener.set_nonblocking(true).unwrap();
TcpListener::from_std(listener).unwrap()
}
// otherwise fall back to local listening
None => TcpListener::bind("0.0.0.0:8080").await.unwrap(),
};
println!("Listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();