2024-07-24 21:59:24 +02:00
|
|
|
use ::app::get_router;
|
2024-08-08 22:14:11 +02:00
|
|
|
use listenfd::ListenFd;
|
2024-07-25 09:21:17 +02:00
|
|
|
use std::env;
|
2024-07-23 20:08:45 +02:00
|
|
|
use std::path::Path;
|
2024-08-08 22:14:11 +02:00
|
|
|
use tokio::net::TcpListener;
|
2024-07-23 20:08:45 +02:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2024-07-24 20:36:16 +02:00
|
|
|
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
|
|
let assets_path = Path::new(&manifest_dir).join("assets");
|
|
|
|
let router = get_router(assets_path.as_path());
|
2024-07-23 20:08:45 +02:00
|
|
|
|
2024-08-08 22:14:11 +02:00
|
|
|
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("localhost:3000").await.unwrap(),
|
|
|
|
};
|
|
|
|
|
|
|
|
println!("Listening on: http://{}", listener.local_addr().unwrap());
|
|
|
|
|
|
|
|
// Run the server with the router
|
|
|
|
axum::serve(listener, router.into_make_service())
|
2024-08-08 15:01:28 +02:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-07-23 20:08:45 +02:00
|
|
|
}
|