fix: lazy DB initialization — useDb() called inside handlers, not at import
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>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import db from '../../utils/db'
|
||||
import { useDb } from '../../utils/db'
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
requireAdmin(event)
|
||||
const db = useDb()
|
||||
const id = getRouterParam(event, 'id')
|
||||
db.prepare('DELETE FROM ideas WHERE id = ?').run(id)
|
||||
return { ok: true }
|
||||
|
||||
Reference in New Issue
Block a user