mailu branch failed
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const db = require('./db');
|
||||
|
||||
const app = express();
|
||||
const port = 5182;
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// API to get messages for a recipient
|
||||
app.get('/api/messages', async (req, res) => {
|
||||
const { recipient } = req.query;
|
||||
if (!recipient) {
|
||||
return res.status(400).send('Recipient is required');
|
||||
}
|
||||
|
||||
try {
|
||||
const [rows] = await db.execute(
|
||||
'SELECT id, sender, subject, body, received_at FROM emails WHERE recipient = ? ORDER BY received_at DESC',
|
||||
[recipient]
|
||||
);
|
||||
res.json(rows);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch emails:', error);
|
||||
res.status(500).send('Failed to fetch emails');
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Backend server listening at http://localhost:${port}`);
|
||||
});
|
||||
Reference in New Issue
Block a user