Files
web-king-arth-maintenance/server.js
T

26 lines
860 B
JavaScript

import express from 'express';
import path from 'path';
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) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
const PORT = process.env.PORT || 80;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});