41 lines
919 B
JavaScript
41 lines
919 B
JavaScript
const express = require('express');
|
|
const mysql = require('mysql2');
|
|
|
|
const app = express();
|
|
|
|
const db = mysql.createConnection({
|
|
host: 'localhost',
|
|
user: 'root',
|
|
password: '12345678',
|
|
database: 'popcen',
|
|
|
|
authPlugins: {
|
|
'caching_sha2_password': mysql.authPlugins.caching_sha2_password
|
|
}
|
|
});
|
|
|
|
db.connect((err) => {
|
|
if (err) {
|
|
console.error('Database connection failed:', err.stack);
|
|
return;
|
|
}
|
|
console.log('Connected to the MySQL database.');
|
|
});
|
|
|
|
app.get('/popcen', (req, res) => {
|
|
const sql = 'SELECT id, uuid, caseid, modified_time FROM popcen';
|
|
|
|
db.query(sql, (err, results) => {
|
|
if (err) {
|
|
console.error(err);
|
|
return res.status(500).send('Server error');
|
|
}
|
|
res.json(results);
|
|
});
|
|
});
|
|
|
|
const PORT = 3000;
|
|
app.listen(PORT, () => {
|
|
console.log(`Server is running on port ${PORT}`);
|
|
});
|