Initial commit: full-stack Bun + Elysia + React template
Elysia.js API with session-based auth (email/password + Google OAuth), role system (USER/ADMIN/SUPER_ADMIN), Prisma + PostgreSQL, React 19 with Mantine UI, TanStack Router, dark theme, and comprehensive test suite (unit, integration, E2E with Lightpanda). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
13
src/lib/db.ts
Normal file
13
src/lib/db.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { PrismaClient } from '../../generated/prisma'
|
||||
|
||||
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ??
|
||||
new PrismaClient({
|
||||
log: process.env.NODE_ENV === 'development' ? ['warn', 'error'] : ['error'],
|
||||
})
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
globalForPrisma.prisma = prisma
|
||||
}
|
||||
19
src/lib/env.ts
Normal file
19
src/lib/env.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
function optional(key: string, fallback: string): string {
|
||||
return process.env[key] ?? fallback
|
||||
}
|
||||
|
||||
function required(key: string): string {
|
||||
const value = process.env[key]
|
||||
if (!value) throw new Error(`Missing required environment variable: ${key}`)
|
||||
return value
|
||||
}
|
||||
|
||||
export const env = {
|
||||
PORT: parseInt(optional('PORT', '3000'), 10),
|
||||
NODE_ENV: optional('NODE_ENV', 'development'),
|
||||
REACT_EDITOR: optional('REACT_EDITOR', 'code'),
|
||||
DATABASE_URL: required('DATABASE_URL'),
|
||||
GOOGLE_CLIENT_ID: required('GOOGLE_CLIENT_ID'),
|
||||
GOOGLE_CLIENT_SECRET: required('GOOGLE_CLIENT_SECRET'),
|
||||
SUPER_ADMIN_EMAILS: optional('SUPER_ADMIN_EMAIL', '').split(',').map(e => e.trim()).filter(Boolean),
|
||||
} as const
|
||||
Reference in New Issue
Block a user