blob: 1947ff8d9cf326a51b90205396e003d124b0e88f (
plain) (
tree)
|
|
use hyper::{
service::{make_service_fn, service_fn},
Server,
};
use std::convert::Infallible; // TODO:
mod config;
mod error;
mod handlers;
mod models;
mod repo;
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::<_, Infallible>(service_fn(|req| handlers::router(req)))
});
let server = Server::bind(&addr).serve(make_svc);
let graceful = server.with_graceful_shutdown(shutdown_signal());
// run until 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");
}
|