From bbd6cb2393cd67fcd94bc86c36ecdf9dae605d83 Mon Sep 17 00:00:00 2001 From: Joachim Hummel Date: Mon, 1 Dec 2025 20:39:02 +0000 Subject: [PATCH] Add public MQTT broker URL configuration for email templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MQTT broker URL in credential emails was using the internal Docker address (mqtt://mosquitto:1883) which is not accessible from external OwnTracks apps. Added MQTT_PUBLIC_BROKER_URL environment variable to configure the publicly accessible broker address for client apps. Changes: - Add MQTT_PUBLIC_BROKER_URL to .env.example with documentation - Update send-credentials route to use public URL with fallback - Maintain backward compatibility with existing MQTT_BROKER_URL 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .env.example | 8 +++++++- app/api/mqtt/send-credentials/route.ts | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 56209d4..4c614cc 100644 --- a/.env.example +++ b/.env.example @@ -29,12 +29,18 @@ ENCRYPTION_KEY=your-32-byte-hex-key-here # MQTT Configuration # ====================================== -# MQTT Broker URL +# MQTT Broker URL (internal - for app container to connect) # Development (local): mqtt://localhost:1883 # Docker Compose: mqtt://mosquitto:1883 # Production: mqtt://your-mqtt-broker:1883 MQTT_BROKER_URL=mqtt://mosquitto:1883 +# MQTT Public Broker URL (external - for OwnTracks apps to connect) +# This is the publicly accessible address that will be sent in emails +# Development (local): mqtt://localhost:1883 +# Production: mqtt://your-public-domain.com:1883 or mqtt://your-server-ip:1883 +MQTT_PUBLIC_BROKER_URL=mqtt://192.168.10.118:1883 + # MQTT Admin Credentials (für MQTT Subscriber und Password File Generation) MQTT_ADMIN_USERNAME=admin MQTT_ADMIN_PASSWORD=admin diff --git a/app/api/mqtt/send-credentials/route.ts b/app/api/mqtt/send-credentials/route.ts index 3fb55a6..29071fe 100644 --- a/app/api/mqtt/send-credentials/route.ts +++ b/app/api/mqtt/send-credentials/route.ts @@ -56,8 +56,9 @@ export async function POST(request: Request) { ); } - // Parse broker URL from environment or use default - const brokerUrl = process.env.MQTT_BROKER_URL || 'mqtt://localhost:1883'; + // Parse public broker URL from environment (for client apps like OwnTracks) + // Use MQTT_PUBLIC_BROKER_URL for external access, fallback to MQTT_BROKER_URL + const brokerUrl = process.env.MQTT_PUBLIC_BROKER_URL || process.env.MQTT_BROKER_URL || 'mqtt://localhost:1883'; const brokerHost = brokerUrl.replace(/^mqtt:\/\//, '').replace(/:\d+$/, ''); const brokerPortMatch = brokerUrl.match(/:(\d+)$/); const brokerPort = brokerPortMatch ? brokerPortMatch[1] : '1883';