summaryrefslogtreecommitdiff
path: root/dichroism/src/main.rs
blob: 442b92dc80870ea2b0b64cae3736a7c31d94d98c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#[macro_use]
extern crate lazy_static;

use actix_web::{App, HttpServer};
use listenfd::ListenFd;

mod config;
mod error;
mod handlers;
mod image_api;
mod result;

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let mut listenfd = ListenFd::from_env();
    let mut server = HttpServer::new(|| {
        App::new()
            .service(handlers::hello)
            .service(handlers::create_image)
            .service(handlers::get_products)
    });

    server = if let Some(l) = listenfd
        .take_tcp_listener(0)
        .expect("Unable to grab TCP listener!")
    {
        // "Debug mode" with cargo watch auto-reloading
        server.listen(l)?
    } else {
        // "Release mode"
        server.bind("127.0.0.1:8000")?
    };

    server.run().await
}