fix:优化整个大屏界面
This commit is contained in:
@@ -12,6 +12,10 @@ app.use(cors())
|
||||
app.use(express.json())
|
||||
app.use('/api', routes)
|
||||
app.get('/api/health', (_, res) => res.json({ ok: true }))
|
||||
app.post('/api/crawler/notify', (_, res) => {
|
||||
notifyCrawlerUpdate()
|
||||
res.json({ ok: true })
|
||||
})
|
||||
|
||||
const server = http.createServer(app)
|
||||
|
||||
@@ -29,6 +33,15 @@ function broadcastSituation() {
|
||||
}
|
||||
setInterval(broadcastSituation, 5000)
|
||||
|
||||
// 供爬虫调用:更新 situation.updated_at 并立即广播
|
||||
function notifyCrawlerUpdate() {
|
||||
try {
|
||||
const db = require('./db')
|
||||
db.prepare("INSERT OR REPLACE INTO situation (id, data, updated_at) VALUES (1, '{}', ?)").run(new Date().toISOString())
|
||||
broadcastSituation()
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`API + WebSocket running at http://localhost:${PORT}`)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user