From 149b736c7449c7b601ad106814407068ab8ce432 Mon Sep 17 00:00:00 2001 From: Agent Date: Tue, 14 Jul 2026 18:29:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85/api/site=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=A7=A3=E5=86=B3=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E7=A9=BA=E7=99=BD=EF=BC=88=E7=BC=BA=E5=B0=91=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E6=95=B0=E6=8D=AEAPI=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/routes/api.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/src/routes/api.js b/backend/src/routes/api.js index 55d5b17..37ba684 100644 --- a/backend/src/routes/api.js +++ b/backend/src/routes/api.js @@ -6,6 +6,22 @@ import { authenticate } from '../middleware/auth.js'; const SECRET = process.env.JWT_SECRET || 'yx-nav-secret-2026'; const router = (app) => { + // ---- 前端公开接口(首页数据) ---- + app.get('/api/site', async (req, res) => { + try { + const [cats] = await pool.query('SELECT * FROM categories ORDER BY sort, id'); + const [links] = await pool.query( + 'SELECT l.*, c.name as categoryName FROM links l JOIN categories c ON l.category_id = c.id WHERE l.is_show = 1 ORDER BY c.sort, l.sort, l.id' + ); + const [sets] = await pool.query('SELECT * FROM settings'); + const settings = {}; + sets.forEach(s => { settings[s.key] = s.value; }); + res.json({ status: 200, result: { data: { categories: cats, links, settings } } }); + } catch { + res.json({ status: 500, message: '加载失败' }); + } + }); + // ---- 公开接口 ---- app.post('/api/auth/login', async (req, res) => { try {