[#6] Add admin panel at /admin
- Password-protected (cabo2026) admin page - View/approve/reject pending options - Delete any option - Toggle polls open/closed - Live stats: voters, options, votes, pending count - Add DELETE /api/options/:id endpoint - Add option_deleted WebSocket broadcast
This commit is contained in:
16
server.js
16
server.js
@@ -15,6 +15,12 @@ const DATA_FILE = path.join(DATA_DIR, 'votes.json');
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// Admin panel
|
||||
app.get('/admin', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'admin.html'));
|
||||
});
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
// ── Data helpers ──────────────────────────────────────────────
|
||||
@@ -189,6 +195,16 @@ app.post('/api/options/:id/approve', (req, res) => {
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
// Delete an option
|
||||
app.delete('/api/options/:id', (req, res) => {
|
||||
const idx = data.options.findIndex(o => o.id === req.params.id);
|
||||
if (idx === -1) return res.status(404).json({ error: 'Not found' });
|
||||
data.options.splice(idx, 1);
|
||||
saveData(data);
|
||||
broadcast({ type: 'option_deleted', id: req.params.id });
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
// Remove vote from an option
|
||||
app.delete('/api/vote/:optionId', (req, res) => {
|
||||
const { voterName } = req.body;
|
||||
|
||||
Reference in New Issue
Block a user