useRuntimeConfig() and better-sqlite3 were being called at module top-level, which crashes during Nitro server startup. Now all DB access is lazy via useDb(), and auth uses process.env directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
13 lines
451 B
TypeScript
13 lines
451 B
TypeScript
import { useDb } from '../../utils/db'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const db = useDb()
|
|
const { text, category } = await readBody(event)
|
|
if (!text?.trim()) {
|
|
throw createError({ statusCode: 400, statusMessage: 'Text is required' })
|
|
}
|
|
const cat = category || 'General'
|
|
const result = db.prepare('INSERT INTO ideas (text, category) VALUES (?, ?)').run(text.trim(), cat)
|
|
return { id: result.lastInsertRowid }
|
|
})
|