blob: 4a5a8b1c09bffecabae787f5eb159dabe04f8a21 (
plain) (
tree)
|
|
use crate::config::CONFIG_INSTANCE;
use crate::error::TwinHError;
use hyper::{
service::{make_service_fn, service_fn},
Server,
};
mod config;
mod error;
mod models;
mod repo;
mod routes;
mod templates;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = CONFIG_INSTANCE.addr;
let make_svc =
make_service_fn(move |_conn| async { Ok::<_, TwinHError>(service_fn(routes::router)) });
let server = Server::bind(&addr).serve(make_svc);
let graceful = server.with_graceful_shutdown(shutdown_signal());
if let Err(e) = graceful.await {
eprintln!("server error: {}", e);
}
Ok(())
}
async fn shutdown_signal() {
// Wait for CTRL+C
tokio::signal::ctrl_c()
.await
.expect("failed to install CTRL+C signal handler");
}
|