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 axum_extra::extract::cookie::Key;
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
|
@ -13,6 +13,8 @@ pub struct Config {
|
||||||
pub zauth_client_secret: String,
|
pub zauth_client_secret: String,
|
||||||
pub database_uri: String,
|
pub database_uri: String,
|
||||||
pub cookies_key: Key,
|
pub cookies_key: Key,
|
||||||
|
pub listen_address: IpAddr,
|
||||||
|
pub port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -39,6 +41,13 @@ impl Config {
|
||||||
.expect("COOKIES_KEY not present")
|
.expect("COOKIES_KEY not present")
|
||||||
.as_ref(),
|
.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 models;
|
||||||
mod routes;
|
mod routes;
|
||||||
|
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use appstate::Appstate;
|
use appstate::Appstate;
|
||||||
use auth::{callback, login};
|
use auth::{callback, login};
|
||||||
use axum::{
|
use axum::{
|
||||||
|
@ -68,7 +70,10 @@ async fn main() {
|
||||||
.with_state(state);
|
.with_state(state);
|
||||||
|
|
||||||
// run our app with hyper, listening globally on port 3000
|
// 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
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
|
|
Loading…
Reference in a new issue