const express = require('express'); const jwt = require('jsonwebtoken'); const router = express.Router(); const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key'; const users = [ { id: 1, username: process.env.ADMIN_USERNAME, password: process.env.ADMIN_PASSWORD } ]; router.post('/login', (req, res) => { const { username, password } = req.body; const user = users.find(u => u.username === username && u.password === password); if (user) { const token = jwt.sign({ id: user.id, username: user.username }, JWT_SECRET, { expiresIn: '1h' }); res.json({ token }); } else { res.status(401).json({ error: '无效的用户名或密码' }); } }); module.exports = router;