blob: 64be9ca5c49594db367dea9e4dc657a463701b71 (
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
25
26
|
use std::str::FromStr;
use anyhow::Context;
use actix_web::{get, App, HttpServer, Responder};
#[get("/")]
async fn hello() -> impl Responder {
"Hello"
}
#[actix_web::main]
async fn main() -> anyhow::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
let bind = std::env::var("HOST").expect("environment: HOST variable not set");
let port = std::env::var("PORT")
.as_ref()
.map(|p| u16::from_str(p))
.expect("environment: PORT variable not set")
.context("Failed to parse port as integer")?;
HttpServer::new(|| App::new().service(hello))
.bind(format!("{}:{}", bind, port))?
.run()
.await
.map_err(anyhow::Error::from)
}
|