aboutsummaryrefslogtreecommitdiff
path: root/src/cli/run_server.rs
blob: d20ac14f03c47b9edc6e958c827ed3be540b0a86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use structopt::StructOpt;

use crate::{db::backend::Connectable, Settings, UrlMap};

#[derive(StructOpt)]
/// Run an HTTP server
pub struct RunServer {
    #[structopt(default_value = "8000")]
    /// The port to listen on
    port: u16,
}

impl RunServer {
    pub fn execute(self, urls: UrlMap, _settings: Settings<impl Connectable>) {
        println!("Starting server at http://127.0.0.1:{}/", self.port);
        let server_task = warp::serve(urls).run(([127, 0, 0, 1], self.port));

        tokio::runtime::Builder::new_multi_thread()
            .enable_all()
            .build()
            .unwrap()
            .block_on(server_task)
    }
}