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



                                           

                                             
 



                         
          
           
           
         
           

              
              
                                           
                                    
 
                           

                                                                                                
 

                                                                                  

                                                                    
                    
                    
 
          

 
                            
                      



                                                           
use crate::error::TwinHError;
use hyper::{
    service::{make_service_fn, service_fn},
    Server,
};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use structopt::StructOpt;

#[macro_use]
extern crate lazy_static;

mod config;
mod error;
mod import;
mod models;
mod repo;
mod routes;
mod templates;

#[tokio::main]
async fn main() -> Result<(), TwinHError> {
    //env_logger::try_init_from_env;

    // create HTTP listener
    let make_svc =
        make_service_fn(move |_conn| async { Ok::<_, TwinHError>(service_fn(routes::router)) });

    // bind server with signal
    let server = Server::bind(&config::INSTANCE.bind_addr.into()).serve(make_svc);
    let graceful = server.with_graceful_shutdown(shutdown_signal());

    // start and run
    graceful.await?;

    Ok(())
}

async fn shutdown_signal() {
    // Wait for CTRL+C
    tokio::signal::ctrl_c()
        .await
        .expect("failed to install CTRL+C signal handler");
}