Skip to content

Commit 1610a75

Browse files
committed
✨ add environment variable to control listen port
1 parent 930caf9 commit 1610a75

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ services:
3737
depends_on:
3838
- platform
3939
environment:
40+
LISTEN_PORT: 1331
4041
V2_SERVICE: ret2shell
4142
# extra_hosts:
4243
# - host.docker.internal:host-gateway

src/config.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,25 @@ pub struct ServerConfig {
4949
impl Config {
5050
pub async fn load() -> Result<Self> {
5151
// Try to load from current directory first
52-
if Path::new("config.toml").exists() {
52+
let mut config: Config = if Path::new("config.toml").exists() {
5353
let content = fs::read_to_string("config.toml").await?;
54-
let config: Config = toml::from_str(&content)?;
55-
return Ok(config);
56-
}
57-
58-
// Try to load from /etc/ret2shell/config.toml
59-
if Path::new("/etc/ret2shell/config.toml").exists() {
54+
toml::from_str(&content)?
55+
} else if Path::new("/etc/ret2shell/config.toml").exists() {
56+
// Try to load from /etc/ret2shell/config.toml
6057
let content = fs::read_to_string("/etc/ret2shell/config.toml").await?;
61-
let config: Config = toml::from_str(&content)?;
62-
return Ok(config);
58+
toml::from_str(&content)?
59+
} else {
60+
anyhow::bail!(
61+
"Config file not found in current directory or /etc/ret2shell/config.toml"
62+
);
63+
};
64+
65+
// Override with environment variables if specified
66+
if let Ok(server_port) = std::env::var("LISTEN_PORT") {
67+
config.server.port = server_port;
6368
}
6469

65-
anyhow::bail!("Config file not found in current directory or /etc/ret2shell/config.toml");
70+
Ok(config)
6671
}
6772

6873
pub fn database_url(&self) -> String {

0 commit comments

Comments
 (0)