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
48
49
50
51
52
53
54
55
56
|
#![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 environment;
mod html;
mod http09;
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<()> {
dotenv::dotenv().ok();
pretty_env_logger::formatted_builder()
.parse_filters(
&std::env::var("RUST_LOG")
.unwrap_or_else(|_| "actix_web=info".to_string()),
)
.init();
if environment::ENVIRONMENT.http09 {
tokio::spawn(http09::serve());
}
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
}
|