step: context base route

This commit is contained in:
Jakob Gegeniger committed 2026-10-16 23:51:47 +02:00
1 parent 84fa3ee3b4
commit 25ca341bb0
9 files changed
+51 -12

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ services:
container_name: web-king-arth-maintenance container_name: web-king-arth-maintenance
restart: unless-stopped restart: unless-stopped
environment: environment:
- VITE_APP_ENV=production MQTT_TOPIC_ROOT: "outdoor/king-arthur/sword/"
networks: networks:
default: default:
+4 -2
View File
@@ -6,8 +6,10 @@ services:
# ports: # ports:
# - "80:80" # - "80:80"
# - "443:443" # - "443:443"
# environment: # MQTT topic root: staging default lives in the app; the productive
# - VITE_APP_ENV=production # system strips the staging/ prefix via this environment variable.
environment:
MQTT_TOPIC_ROOT: "outdoor/king-arthur/sword/"
networks: networks:
default: default:
+1
View File
@@ -8,6 +8,7 @@
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="/config.js"></script>
<script type="module" src="/src/main.ts"></script> <script type="module" src="/src/main.ts"></script>
</body> </body>
</html> </html>
+6
View File
@@ -0,0 +1,6 @@
// Local development defaults, served by the Vite dev server.
// In Docker, server.js serves /config.js dynamically from the
// MQTT_TOPIC_ROOT environment variable instead (this copy is shadowed).
window.__APP_CONFIG__ = {
mqttTopicRoot: 'staging/outdoor/king-arthur/sword/'
};
+8
View File
@@ -5,6 +5,14 @@ import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url)); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express(); const app = express();
// Runtime app configuration, served as window.__APP_CONFIG__.
// Must be registered before the static/catch-all routes.
const mqttTopicRoot = process.env.MQTT_TOPIC_ROOT || 'staging/outdoor/king-arthur/sword/';
app.get('/config.js', (req, res) => {
res.type('application/javascript').send(`window.__APP_CONFIG__ = ${JSON.stringify({ mqttTopicRoot })};`);
});
console.log(`MQTT topic root: ${mqttTopicRoot}`);
app.use(express.static(path.join(__dirname, 'dist'))); app.use(express.static(path.join(__dirname, 'dist')));
app.get('*', (req, res) => { app.get('*', (req, res) => {
+21
View File
@@ -0,0 +1,21 @@
interface AppConfig {
mqttTopicRoot?: string
}
declare global {
interface Window {
__APP_CONFIG__?: AppConfig
}
}
const defaultTopicRoot = 'staging/outdoor/king-arthur/sword/'
/**
* Runtime configuration injected by the server (/config.js -> window.__APP_CONFIG__).
* Falls back to the Vite build-time env var, then to the staging default.
*/
export function getMqttTopicRoot(): string {
const configured = window.__APP_CONFIG__?.mqttTopicRoot ?? import.meta.env.VITE_MQTT_TOPIC_ROOT
const topicRoot = configured || defaultTopicRoot
return topicRoot.endsWith('/') ? topicRoot : topicRoot + '/'
}
+8 -5
View File
@@ -1,10 +1,11 @@
import mqtt from 'mqtt' import mqtt from 'mqtt'
import { getMqttTopicRoot } from './appConfig'
const mqttBrokerHost = 'mqtt.excaliburs-erben.de' const mqttBrokerHost = 'mqtt.excaliburs-erben.de'
const mqttBrokerPort = 443 // 9001 if not secure const mqttBrokerPort = 443 // 9001 if not secure
const mqttBrokerPath = '/mqtt' const mqttBrokerPath = '/mqtt'
const mqttUseTls = true const mqttUseTls = true
const mqttTopicRoot = 'staging/outdoor/king-arthur/sword/' const mqttTopicRoot = getMqttTopicRoot()
const mqttMessage = 'start-hit' const mqttMessage = 'start-hit'
const mqttUser = "exodususer"; const mqttUser = "exodususer";
const mqttPassword = "awesomeexodusoutdooradventures"; const mqttPassword = "awesomeexodusoutdooradventures";
@@ -138,8 +139,8 @@ export function enterMaintananceMode(
const verMqttTopic = mqttTopicRoot + 'ver' const verMqttTopic = mqttTopicRoot + 'ver'
client.on('connect', () => { client.on('connect', () => {
publishCmd(client, "SetMaintanance") publishCmd(client, "setMaintanance")
client.subscribe(statMqttTopic, { qos: 1 }, (error) => { client.subscribe([statMqttTopic, verMqttTopic], { qos: 1 }, (error) => {
if (error) { if (error) {
console.error('MQTT subscribe failed:', error) console.error('MQTT subscribe failed:', error)
} }
@@ -166,6 +167,7 @@ export function enterMaintananceMode(
} }
if (topic === verMqttTopic) { if (topic === verMqttTopic) {
const messageStr = message.toString() const messageStr = message.toString()
console.log(messageStr)
verCallback(messageStr) verCallback(messageStr)
} }
}) })
@@ -175,8 +177,9 @@ export function enterMaintananceMode(
export function exitMaintananceMode(client: mqtt.MqttClient): void { export function exitMaintananceMode(client: mqtt.MqttClient): void {
publishCmd(client, "Exit") publishCmd(client, "Exit")
const mqttTopic = mqttTopicRoot + 'stat' const statMqttTopic = mqttTopicRoot + 'stat'
client.unsubscribe(mqttTopic, (error) => { const verMqttTopic = mqttTopicRoot + 'ver'
client.unsubscribe([statMqttTopic, verMqttTopic], (error) => {
if (error) { if (error) {
console.error('MQTT unsubscribe failed:', error) console.error('MQTT unsubscribe failed:', error)
} }
+1 -1
View File
@@ -7,7 +7,7 @@
<div class="info-section"> <div class="info-section">
<div class="info-box"> <div class="info-box">
<h3>Version</h3> <h3>Version</h3>
<p id="version-number">0.9.0</p> <p id="version-number">1.0.0</p>
</div> </div>
<div class="info-box"> <div class="info-box">
<h3>Service Hotline</h3> <h3>Service Hotline</h3>
+1 -3
View File
@@ -190,6 +190,4 @@ onUnmounted(() => {
}) })
</script> </script>
<style scoped> <style scoped></style>
</style>