-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (36 loc) · 1.15 KB
/
server.js
File metadata and controls
42 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const chatRoutes = require('./routes/chatRoutes');
const path = require('path');
const { testConnection, setConfig, getSchemaMetadata } = require('./services/mysqlService');
const app = express();
app.use(cors());
app.use(bodyParser.json());
// MySQL config: set/test
app.post('/api/mysql/config', async (req, res) => {
const config = req.body;
const result = await testConnection(config);
if (result.success) {
setConfig(config);
res.json({ success: true });
} else {
res.status(400).json({ success: false, error: result.error });
}
});
// Get MySQL schema metadata
app.get('/api/mysql/schema', async (req, res) => {
try {
const schema = await getSchemaMetadata();
if (!schema) return res.status(400).json({ error: 'Not connected' });
res.json({ schema });
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.use('/api', chatRoutes);
app.use(express.static(path.join(__dirname, 'public')));
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});