From 9eaa9c1a17a2ee32655e2ac4868e775cd57976c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Fri, 28 Sep 2018 13:46:13 +0200 Subject: [PATCH] Add WEBSOCKET_ADDRESS config option (Fixes #199) --- .env | 3 ++- src/api/notifications.rs | 3 ++- src/main.rs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 4c9a9ec..b04b632 100644 --- a/.env +++ b/.env @@ -14,7 +14,8 @@ # WEB_VAULT_FOLDER=web-vault/ # WEB_VAULT_ENABLED=true -## Controls the WebSocket server port +## Controls the WebSocket server address and port +# WEBSOCKET_ADDRESS=0.0.0.0 # WEBSOCKET_PORT=3012 ## Controls if new users can register diff --git a/src/api/notifications.rs b/src/api/notifications.rs index 377b59d..2e4386b 100644 --- a/src/api/notifications.rs +++ b/src/api/notifications.rs @@ -250,6 +250,7 @@ impl WebSocketUsers { } // NOTE: The last modified date needs to be updated before calling these methods + #[allow(dead_code)] pub fn send_user_update(&self, ut: UpdateType, user: &User) { let data = create_update( vec![ @@ -358,7 +359,7 @@ pub fn start_notification_server() -> WebSocketUsers { thread::spawn(move || { WebSocket::new(factory) .unwrap() - .listen(format!("0.0.0.0:{}", CONFIG.websocket_port)) + .listen(&CONFIG.websocket_url) .unwrap(); }); diff --git a/src/main.rs b/src/main.rs index 0633524..f6e58c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -232,7 +232,7 @@ pub struct Config { web_vault_folder: String, web_vault_enabled: bool, - websocket_port: i32, + websocket_url: String, local_icon_extractor: bool, signups_allowed: bool, @@ -268,7 +268,7 @@ impl Config { web_vault_folder: get_env_or("WEB_VAULT_FOLDER", "web-vault/".into()), web_vault_enabled: get_env_or("WEB_VAULT_ENABLED", true), - websocket_port: get_env_or("WEBSOCKET_PORT", 3012), + websocket_url: format!("{}:{}", get_env_or("WEBSOCKET_ADDRESS", "0.0.0.0".to_string()), get_env_or("WEBSOCKET_PORT", 3012)), local_icon_extractor: get_env_or("LOCAL_ICON_EXTRACTOR", false), signups_allowed: get_env_or("SIGNUPS_ALLOWED", true),