補上歷史戰績列表與 NAS 部署說明

This commit is contained in:
2026-04-15 23:04:16 +08:00
parent 7fc8e2698b
commit b0908b4d3c
8 changed files with 472 additions and 72 deletions

View File

@@ -169,6 +169,38 @@ app.post('/api/history', async (request, response) => {
}
})
app.get('/api/history', async (_request, response) => {
if (!pool) {
response.status(500).json({
ok: false,
message: `DB 尚未設定完成,缺少 ${missingEnv.join(', ')}`,
})
return
}
try {
await ensureHistoryTable(pool, historyTableName)
const [rows] = await pool.execute(
`
SELECT id, time, dayOfWeek, score, winScore, type, players, team, scoreList
FROM \`${historyTableName}\`
ORDER BY id DESC
`,
)
response.json({
ok: true,
data: rows,
})
} catch (error) {
console.error('history load error:', error)
response.status(500).json({
ok: false,
message: error instanceof Error ? error.message : '讀取歷史戰績失敗。',
})
}
})
if (distReady) {
app.use(express.static(distDir))