step: context base route
This commit is contained in:
1 parent
84fa3ee3b4
commit
4f8eaca8e1
9 files changed
+51
-12
No files matched your search
@@ -5,7 +5,7 @@ services:
|
||||
container_name: web-king-arth-maintenance
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- VITE_APP_ENV=production
|
||||
MQTT_TOPIC_ROOT: "outdoor/king-arthur/sword/"
|
||||
|
||||
networks:
|
||||
default:
|
||||
|
||||
+4
-2
@@ -6,8 +6,10 @@ services:
|
||||
# ports:
|
||||
# - "80:80"
|
||||
# - "443:443"
|
||||
# environment:
|
||||
# - VITE_APP_ENV=production
|
||||
# MQTT topic root: staging default lives in the app; the productive
|
||||
# system strips the staging/ prefix via this environment variable.
|
||||
environment:
|
||||
MQTT_TOPIC_ROOT: "outdoor/king-arthur/sword/"
|
||||
|
||||
networks:
|
||||
default:
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="/config.js"></script>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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/'
|
||||
};
|
||||
@@ -5,6 +5,14 @@ import { fileURLToPath } from 'url';
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
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.get('*', (req, res) => {
|
||||
|
||||
@@ -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 + '/'
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import mqtt from 'mqtt'
|
||||
import { getMqttTopicRoot } from './appConfig'
|
||||
|
||||
const mqttBrokerHost = 'mqtt.excaliburs-erben.de'
|
||||
const mqttBrokerPort = 443 // 9001 if not secure
|
||||
const mqttBrokerPath = '/mqtt'
|
||||
const mqttUseTls = true
|
||||
const mqttTopicRoot = 'staging/outdoor/king-arthur/sword/'
|
||||
const mqttTopicRoot = getMqttTopicRoot()
|
||||
const mqttMessage = 'start-hit'
|
||||
const mqttUser = "exodususer";
|
||||
const mqttPassword = "awesomeexodusoutdooradventures";
|
||||
@@ -138,8 +139,8 @@ export function enterMaintananceMode(
|
||||
const verMqttTopic = mqttTopicRoot + 'ver'
|
||||
|
||||
client.on('connect', () => {
|
||||
publishCmd(client, "SetMaintanance")
|
||||
client.subscribe(statMqttTopic, { qos: 1 }, (error) => {
|
||||
publishCmd(client, "setMaintanance")
|
||||
client.subscribe([statMqttTopic, verMqttTopic], { qos: 1 }, (error) => {
|
||||
if (error) {
|
||||
console.error('MQTT subscribe failed:', error)
|
||||
}
|
||||
@@ -166,6 +167,7 @@ export function enterMaintananceMode(
|
||||
}
|
||||
if (topic === verMqttTopic) {
|
||||
const messageStr = message.toString()
|
||||
console.log(messageStr)
|
||||
verCallback(messageStr)
|
||||
}
|
||||
})
|
||||
@@ -175,8 +177,9 @@ export function enterMaintananceMode(
|
||||
|
||||
export function exitMaintananceMode(client: mqtt.MqttClient): void {
|
||||
publishCmd(client, "Exit")
|
||||
const mqttTopic = mqttTopicRoot + 'stat'
|
||||
client.unsubscribe(mqttTopic, (error) => {
|
||||
const statMqttTopic = mqttTopicRoot + 'stat'
|
||||
const verMqttTopic = mqttTopicRoot + 'ver'
|
||||
client.unsubscribe([statMqttTopic, verMqttTopic], (error) => {
|
||||
if (error) {
|
||||
console.error('MQTT unsubscribe failed:', error)
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
<div class="info-section">
|
||||
<div class="info-box">
|
||||
<h3>Version</h3>
|
||||
<p id="version-number">0.9.0</p>
|
||||
<p id="version-number">1.0.0</p>
|
||||
</div>
|
||||
<div class="info-box">
|
||||
<h3>Service Hotline</h3>
|
||||
|
||||
@@ -190,6 +190,4 @@ onUnmounted(() => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
<style scoped></style>
|
||||
Reference in new issue
Block a user