Add public MQTT broker URL configuration for email templates
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 <noreply@anthropic.com>
This commit is contained in:
@@ -29,12 +29,18 @@ ENCRYPTION_KEY=your-32-byte-hex-key-here
|
|||||||
# MQTT Configuration
|
# MQTT Configuration
|
||||||
# ======================================
|
# ======================================
|
||||||
|
|
||||||
# MQTT Broker URL
|
# MQTT Broker URL (internal - for app container to connect)
|
||||||
# Development (local): mqtt://localhost:1883
|
# Development (local): mqtt://localhost:1883
|
||||||
# Docker Compose: mqtt://mosquitto:1883
|
# Docker Compose: mqtt://mosquitto:1883
|
||||||
# Production: mqtt://your-mqtt-broker:1883
|
# Production: mqtt://your-mqtt-broker:1883
|
||||||
MQTT_BROKER_URL=mqtt://mosquitto: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 Credentials (für MQTT Subscriber und Password File Generation)
|
||||||
MQTT_ADMIN_USERNAME=admin
|
MQTT_ADMIN_USERNAME=admin
|
||||||
MQTT_ADMIN_PASSWORD=admin
|
MQTT_ADMIN_PASSWORD=admin
|
||||||
|
|||||||
@@ -56,8 +56,9 @@ export async function POST(request: Request) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse broker URL from environment or use default
|
// Parse public broker URL from environment (for client apps like OwnTracks)
|
||||||
const brokerUrl = process.env.MQTT_BROKER_URL || 'mqtt://localhost:1883';
|
// 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 brokerHost = brokerUrl.replace(/^mqtt:\/\//, '').replace(/:\d+$/, '');
|
||||||
const brokerPortMatch = brokerUrl.match(/:(\d+)$/);
|
const brokerPortMatch = brokerUrl.match(/:(\d+)$/);
|
||||||
const brokerPort = brokerPortMatch ? brokerPortMatch[1] : '1883';
|
const brokerPort = brokerPortMatch ? brokerPortMatch[1] : '1883';
|
||||||
|
|||||||
Reference in New Issue
Block a user