refactor: Modularize server into separate concerns
Split monolithic index.ts (~1400 lines) into modular structure: - config.ts: Server configuration and constants - db/: Database initialization, migrations, and seeds - routes/: API handlers by domain (themes, canvas, components, etc.) - services/: Terminal WebSocket server - utils/: CORS helpers Entry point now only coordinates initialization.
This commit is contained in:
24
server/routes/history.ts
Normal file
24
server/routes/history.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { db } from '../db'
|
||||
import { jsonResponse } from '../utils/cors'
|
||||
|
||||
export async function handleHistory(req: Request, url: URL) {
|
||||
if (req.method === 'GET') {
|
||||
const limit = parseInt(url.searchParams.get('limit') || '50')
|
||||
const rows = db.query('SELECT * FROM history ORDER BY id DESC LIMIT ?').all(limit)
|
||||
return jsonResponse(rows)
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const body = await req.json()
|
||||
const stmt = db.prepare('INSERT INTO history (tool_name, args, result) VALUES (?, ?, ?)')
|
||||
stmt.run(body.tool_name, JSON.stringify(body.args), body.result)
|
||||
return jsonResponse({ success: true })
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
db.run('DELETE FROM history')
|
||||
return jsonResponse({ success: true })
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user