aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: b7e31295cb35bc9dbd014589c7a43d767dfaca91 (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
36
37
38
39
40
41
42
43
44
45
46
47
#![deny(
  warnings,
  nonstandard_style,
  unused,
  future_incompatible,
  rust_2018_idioms,
  unsafe_code
)]
#![deny(clippy::all, clippy::nursery, clippy::pedantic)]
#![recursion_limit = "128"]
#![allow(clippy::cast_precision_loss)]

mod html;
mod response;
mod url;

#[macro_use]
extern crate log;

use {actix_web::web, response::default, std::env::var};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
  std::env::set_var("RUST_LOG", "actix_web=info");
  dotenv::dotenv().ok();
  pretty_env_logger::init();

  actix_web::HttpServer::new(move || {
    actix_web::App::new()
      .default_service(web::get().to(default))
      .wrap(actix_web::middleware::Logger::default())
  })
  .bind((
    "0.0.0.0",
    var("PORT").map_or(80, |port| match port.parse::<_>() {
      Ok(port) => port,
      Err(e) => {
        warn!("could not use PORT from environment variables: {e}");
        warn!("proceeding with default port: 80");

        80
      }
    }),
  ))?
  .run()
  .await
}