From 7baf628e0ee2d970e5e0eca344d1425bc2c391a6 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Sat, 4 Apr 2026 17:08:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9B=91=E5=90=AC=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 1 + server/index.js | 10 ++++++---- server/init-db.js | 12 ++++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 610fc77..fe88e7d 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,7 @@ MYSQL_PASSWORD=your_password MYSQL_DATABASE=display_wall # Server Configuration +HOST=0.0.0.0 PORT=3000 # Data refresh interval (ms) diff --git a/server/index.js b/server/index.js index d64964d..9f961db 100644 --- a/server/index.js +++ b/server/index.js @@ -7,6 +7,7 @@ const prometheusService = require('./prometheus-service'); const app = express(); const PORT = process.env.PORT || 3000; +const HOST = process.env.HOST || '0.0.0.0'; app.use(cors()); app.use(express.json()); @@ -71,7 +72,7 @@ app.post('/api/setup/init', async (req, res) => { id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, url VARCHAR(500) NOT NULL, - description TEXT DEFAULT '', + description TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci @@ -86,6 +87,7 @@ MYSQL_USER=${user || 'root'} MYSQL_PASSWORD=${password || ''} MYSQL_DATABASE=${dbName} PORT=${process.env.PORT || 3000} +HOST=${process.env.HOST || '0.0.0.0'} REFRESH_INTERVAL=${process.env.REFRESH_INTERVAL || 5000} `; fs.writeFileSync(path.join(__dirname, '..', '.env'), envContent); @@ -355,8 +357,8 @@ app.get('*', (req, res) => { res.sendFile(path.join(__dirname, '..', 'public', 'index.html')); }); -app.listen(PORT, () => { +app.listen(PORT, HOST, () => { console.log(`\n 🚀 Data Visualization Display Wall`); - console.log(` 📊 Server running at http://localhost:${PORT}`); - console.log(` ⚙️ Configure Prometheus sources at http://localhost:${PORT}/settings\n`); + console.log(` 📊 Server running at http://${HOST === '0.0.0.0' ? 'localhost' : HOST}:${PORT}`); + console.log(` ⚙️ Configure Prometheus sources at http://${HOST === '0.0.0.0' ? 'localhost' : HOST}:${PORT}/settings\n`); }); diff --git a/server/init-db.js b/server/init-db.js index ad14ccf..9a3fb5b 100644 --- a/server/init-db.js +++ b/server/init-db.js @@ -26,12 +26,12 @@ async function initDatabase() { // Create prometheus_sources table await connection.query(` - CREATE TABLE IF NOT EXISTS prometheus_sources ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) NOT NULL, - url VARCHAR(500) NOT NULL, - description TEXT DEFAULT '', - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + CREATE TABLE IF NOT EXISTS prometheus_sources ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL, + url VARCHAR(500) NOT NULL, + description TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `);