make listen address and port env
This commit is contained in:
parent
d6fa0cf59a
commit
ac1c466866
2 changed files with 18 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{env, sync::OnceLock};
|
||||
use std::{env, net::IpAddr, sync::OnceLock};
|
||||
|
||||
use axum_extra::extract::cookie::Key;
|
||||
use dotenvy::dotenv;
|
||||
|
@ -13,6 +13,8 @@ pub struct Config {
|
|||
pub zauth_client_secret: String,
|
||||
pub database_uri: String,
|
||||
pub cookies_key: Key,
|
||||
pub listen_address: IpAddr,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -39,6 +41,13 @@ impl Config {
|
|||
.expect("COOKIES_KEY not present")
|
||||
.as_ref(),
|
||||
),
|
||||
listen_address: env::var("LISTEN_ADDRESS")
|
||||
.unwrap_or("127.0.0.1".to_string())
|
||||
.parse()
|
||||
.expect("LISTEN_ADDRESS is invalid"),
|
||||
port: env::var("PORT")
|
||||
.map(|v| v.parse::<u16>().expect("PORT is invalid"))
|
||||
.unwrap_or(8080),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ mod error;
|
|||
mod models;
|
||||
mod routes;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use appstate::Appstate;
|
||||
use auth::{callback, login};
|
||||
use axum::{
|
||||
|
@ -68,7 +70,10 @@ async fn main() {
|
|||
.with_state(state);
|
||||
|
||||
// run our app with hyper, listening globally on port 3000
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
|
||||
let listener = tokio::net::TcpListener::bind(SocketAddr::from((
|
||||
Config::get().listen_address,
|
||||
Config::get().port,
|
||||
)))
|
||||
.await
|
||||
.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
|
|
Loading…
Reference in a new issue