Allow configuring listen options.

This commit is contained in:
Kavin 2022-11-02 18:42:12 +00:00
parent e5de68aa0c
commit 3ab1529ba7
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -1,3 +1,4 @@
use std::env;
use std::error::Error;
use actix_web::{App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer, web};
@ -12,15 +13,18 @@ use reqwest::{Client, Request, Url};
async fn main() -> std::io::Result<()> {
println!("Running server!");
HttpServer::new(|| {
let server =HttpServer::new(|| {
// match all requests
App::new()
App::new()
.default_service(web::to(index))
})
.bind("0.0.0.0:8080")?
.bind_uds("./socket/actix.sock")?
.run()
.await
});
// get port from env
if env::var("UDS").is_ok() {
server.bind_uds("./socket/actix.sock")?
} else {
let bind = env::var("BIND").unwrap_or_else(|_| "0.0.0.0:8080".to_string());
server.bind(bind)?
}.run().await
}
lazy_static!(