Skip to content

Commit 724fedd

Browse files
waleedclaude
andcommitted
debug: add diagnostic endpoints to test NODE_ENV and database pooling
Added two diagnostic endpoints: - /api/debug/env: Shows NODE_ENV and globalThis.database status - /api/debug/db-test: Measures database query performance 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9763d37 commit 724fedd

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { db } from '@sim/db'
2+
import { sql } from 'drizzle-orm'
3+
import { NextResponse } from 'next/server'
4+
5+
export const dynamic = 'force-dynamic'
6+
7+
export async function GET() {
8+
const measurements: Record<string, number> = {}
9+
10+
try {
11+
// Test 1: Simple query
12+
const t1 = performance.now()
13+
await db.execute(sql`SELECT 1`)
14+
measurements.simpleQuery = performance.now() - t1
15+
16+
// Test 2: Check if globalThis caching is working
17+
const t2 = performance.now()
18+
const dbRef1 = globalThis.database
19+
measurements.checkGlobalThis = performance.now() - t2
20+
21+
// Test 3: Another simple query
22+
const t3 = performance.now()
23+
await db.execute(sql`SELECT 1`)
24+
measurements.simpleQuery2 = performance.now() - t3
25+
26+
// Test 4: Check connection
27+
const t4 = performance.now()
28+
await db.execute(sql`SELECT current_database(), current_user, version()`)
29+
measurements.connectionInfo = performance.now() - t4
30+
31+
return NextResponse.json({
32+
success: true,
33+
NODE_ENV: process.env.NODE_ENV,
34+
hasCachedDatabase: !!globalThis.database,
35+
isSameDbInstance: dbRef1 === globalThis.database,
36+
measurements,
37+
timestamp: new Date().toISOString(),
38+
})
39+
} catch (error: any) {
40+
return NextResponse.json(
41+
{
42+
success: false,
43+
error: error.message,
44+
NODE_ENV: process.env.NODE_ENV,
45+
hasCachedDatabase: !!globalThis.database,
46+
measurements,
47+
timestamp: new Date().toISOString(),
48+
},
49+
{ status: 500 }
50+
)
51+
}
52+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NextResponse } from 'next/server'
2+
3+
export const dynamic = 'force-dynamic'
4+
5+
export async function GET() {
6+
return NextResponse.json({
7+
NODE_ENV: process.env.NODE_ENV,
8+
nodeVersion: process.version,
9+
platform: process.platform,
10+
arch: process.arch,
11+
uptime: process.uptime(),
12+
memoryUsage: process.memoryUsage(),
13+
// Check if globalThis.database exists
14+
hasCachedDatabase: !!globalThis.database,
15+
timestamp: new Date().toISOString(),
16+
})
17+
}

0 commit comments

Comments
 (0)