Skip to content

Commit

Permalink
add API_HOST env var
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Nov 5, 2023
1 parent 2f61733 commit 363250a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
APP_ENV=dev
API_HOST=127.0.0.1
API_PORT=8665
DATABASE_HOST=localhost
DATABASE_PORT=3306
Expand All @@ -18,4 +19,4 @@ REDIS_PASSWORD=
REDIS_DATABASE=0
BEATMAPS_PATH=
SERVICE_READINESS_TIMEOUT=60
RUST_LOG=performance_service=info
RUST_LOG=performance_service=info
3 changes: 2 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn api_router() -> Router {

pub async fn serve(ctx: Context) -> anyhow::Result<()> {
let server_port = ctx.config.api_port.unwrap();
let server_host = ctx.config.api_host.clone().unwrap();

let app = api_router().layer(
ServiceBuilder::new()
Expand All @@ -29,7 +30,7 @@ pub async fn serve(ctx: Context) -> anyhow::Result<()> {
);

log::info!("serving on {}", server_port);
axum::Server::bind(&format!("127.0.0.1:{}", server_port).parse()?)
axum::Server::bind(&format!("{}:{}", server_host, server_port).parse()?)
.serve(app.into_make_service())
.await?;

Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ pub struct Config {
#[clap(long, env)]
pub app_component: String,

#[clap(long, env)]
pub api_host: Option<String>,

#[clap(long, env)]
pub api_port: Option<u16>,

Expand Down

0 comments on commit 363250a

Please sign in to comment.