diff --git a/README.md b/README.md index 63a689b..33840bc 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ # 构建 cargo build --release -# 运行(默认监听 0.0.0.0:1323) +# 运行(默认监听 127.0.0.1:1323) ./target/release/font_obfuscator # 自定义端口 @@ -38,6 +38,7 @@ PORT=8080 ./target/release/font_obfuscator | 变量 | 默认值 | 说明 | |------|--------|------| | `PORT` | `1323` | 服务监听端口 | +| `LISTEN_ADDR` | `127.0.0.1` | 服务监听地址 | | `BASE_FONT_PATH` | `base-font/KaiGenGothicCN-Regular.ttf` | 基础字体文件路径 | ### API @@ -159,7 +160,7 @@ Built with Rust, using Google's [fontations](https://github.com/googlefonts/font # Build cargo build --release -# Run (listens on 0.0.0.0:1323 by default) +# Run (listens on 127.0.0.1:1323 by default) ./target/release/font_obfuscator # Custom port @@ -171,6 +172,7 @@ PORT=8080 ./target/release/font_obfuscator | Variable | Default | Description | |----------|---------|-------------| | `PORT` | `1323` | Server listening port | +| `LISTEN_ADDR` | `127.0.0.1` | Server listen address | | `BASE_FONT_PATH` | `base-font/KaiGenGothicCN-Regular.ttf` | Base font file path | ### API diff --git a/src/config.rs b/src/config.rs index 82c8986..95f7289 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,7 @@ impl Default for FontConfig { #[derive(Clone)] pub struct AppConfig { pub port: u16, + pub listen_addr: String, pub font: FontConfig, pub base_font_path: String, } @@ -35,6 +36,7 @@ impl AppConfig { .ok() .and_then(|p| p.parse().ok()) .unwrap_or(1323), + listen_addr: env::var("LISTEN_ADDR").unwrap_or_else(|_| "127.0.0.1".into()), font: FontConfig::default(), base_font_path: env::var("BASE_FONT_PATH") .unwrap_or_else(|_| "base-font/KaiGenGothicCN-Regular.ttf".into()), diff --git a/src/main.rs b/src/main.rs index 6667c28..4ad0333 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ async fn main() { }) }); - let addr = format!("0.0.0.0:{}", config.port); + let addr = format!("{}:{}", config.listen_addr, config.port); tracing::info!("服务启动于 {}", addr); let state = Arc::new(AppState { config, font_data });