添加监听地址

This commit is contained in:
CN-JS-HuiBai
2026-04-04 17:08:08 +08:00
parent 38c6b18ae6
commit 7baf628e0e
3 changed files with 13 additions and 10 deletions

View File

@@ -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)

View File

@@ -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`);
});

View File

@@ -30,7 +30,7 @@ async function initDatabase() {
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