補上歷史戰績列表與 NAS 部署說明
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user