DIIDKMIXQENUQIOIFHT62KAX4WL5MJWEB5BXHGUYCDSKIPRQVPOAC
use std::convert::Infallible;
use std::net::SocketAddr;
use hyper::{
Body,
Request,
Response,
Server,
service::{
service_fn,
make_service_fn
}
};
use zhur_common::{
log::*,
pretty_env_logger
};
async fn handle_reqs(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
Ok(Response::new("Hi there!".into()))
}
use zhur_common::init_logger;
use zhur_gate::start_server;
pretty_env_logger::init();
let port = match std::env::var("ZHUR_GATE_PORT") {
Ok(v) => match v.parse::<u16>() {
Ok(n) => n,
_ => {
error!("ZHUR_GATE_PORT set to invalid value \"{}\", exiting.", &v);
return;
}
},
_ => {
warn!("ZHUR_GATE_PORT env var not set. Assuming port 8080.");
8080
}
};
let addr = SocketAddr::from(([127, 0, 0, 1], port));
let make_svc = make_service_fn(|_conn| async {
Ok::<_, Infallible>(service_fn(handle_reqs))
});
let server = Server::bind(&addr).serve(make_svc);
if let Err(e) = server.await {
error!("HTTP server error: {}", e);
}
init_logger();
start_server().await;
use std::convert::Infallible;
use std::net::SocketAddr;
use hyper::{
Body,
Request,
Response,
Server,
service::{
service_fn,
make_service_fn
}
};
use zhur_common::log::*;
async fn handle_reqs(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
Ok(Response::new("Hi there!".into()))
}
/// Runs a Hyper HTTP server.
pub async fn start_server() {
let port = match std::env::var("ZHUR_GATE_PORT") {
Ok(v) => match v.parse::<u16>() {
Ok(n) => n,
_ => {
error!("ZHUR_GATE_PORT set to invalid value \"{}\", exiting.", &v);
return;
}
},
_ => {
warn!("ZHUR_GATE_PORT env var not set. Assuming port 8080.");
8080
}
};
let addr = SocketAddr::from(([127, 0, 0, 1], port));
let make_svc = make_service_fn(|_conn| async {
Ok::<_, Infallible>(service_fn(handle_reqs))
});
let server = Server::bind(&addr).serve(make_svc);
if let Err(e) = server.await {
error!("HTTP server error: {}", e);
}
}