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:
27
server/routes/config.ts
Normal file
27
server/routes/config.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { db } from '../db'
|
||||
import { jsonResponse } from '../utils/cors'
|
||||
|
||||
export async function handleConfig(req: Request, url: URL) {
|
||||
if (req.method === 'GET') {
|
||||
const key = url.searchParams.get('key')
|
||||
if (key) {
|
||||
const row = db.query('SELECT value FROM config WHERE key = ?').get(key) as { value: string } | null
|
||||
return jsonResponse({ value: row?.value || null })
|
||||
}
|
||||
const rows = db.query('SELECT * FROM config').all()
|
||||
return jsonResponse(rows)
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
const body = await req.json()
|
||||
const stmt = db.prepare('INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)')
|
||||
stmt.run(body.key, body.value)
|
||||
return jsonResponse({ success: true })
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function handleHealth() {
|
||||
return jsonResponse({ status: 'ok', timestamp: new Date().toISOString() })
|
||||
}
|
||||
Reference in New Issue
Block a user