feat: graceful shutdown via /api/shutdown

This commit is contained in:
zlm committed 2026-06-10 15:01:03 +08:00
1 parent 44e03d8e9a
commit 1e92cc85fe
2 files changed
+18 -5

No files matched your search

+11 -1
View File
@@ -63,9 +63,19 @@ app.get('/web/*', (c) => {
return c.newResponse(content, 200, { 'Content-Type': MIME[ext] || 'application/octet-stream' })
})
app.get('/api/shutdown', (c) => {
logger.info('Server', '收到关闭请求,正在停止...')
scanner.stop()
setTimeout(() => {
server.close()
process.exit(0)
}, 500)
return c.json({ success: true, message: '正在关闭' })
})
const PORT = parseInt(process.env.PORT || '3000', 10)
serve({
const server = serve({
fetch: app.fetch,
port: PORT,
}, (info) => {