summaryrefslogblamecommitdiff
path: root/src/main.rs
blob: 168a5f59e318ae1adfcfb4a0cec5f008af147b6a (plain) (tree)
1
2
3
4
5
6
7
8
9




                                           
 
           
             
           

              
              

                                                           
 

                                                                                                  
 
                                                     

                                                                    
                                


                                         

          

 
                            
                      



                                                           
use hyper::{
    service::{make_service_fn, service_fn},
    Server,
};
use std::convert::Infallible; // TODO:

mod config;
mod handlers;
mod models;
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(handlers::router)) });

    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");
}