chore: scaffold Nuxt 4 app with Postgres, tooling and health route
Nuxt 4 (app/ structure) + TypeScript, ESLint, Vitest + @nuxt/test-utils, Drizzle + pg, a /api/health route with a DB ping, and a dev docker-compose (app + Postgres). Verified: pnpm test, lint, and build pass; the built server answers /api/health.
This commit is contained in:
21
server/db/client.ts
Normal file
21
server/db/client.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import pg from 'pg'
|
||||
|
||||
let pool: pg.Pool | undefined
|
||||
|
||||
/** Lazily-created shared Postgres connection pool. */
|
||||
export function getPool(): pg.Pool {
|
||||
if (!pool) {
|
||||
pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
|
||||
}
|
||||
return pool
|
||||
}
|
||||
|
||||
/** Liveness probe for the database, used by /api/health. */
|
||||
export async function checkDb(): Promise<'up' | 'down'> {
|
||||
try {
|
||||
await getPool().query('select 1')
|
||||
return 'up'
|
||||
} catch {
|
||||
return 'down'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user