Add server infrastructure with API routes and middleware

- Create API route structure (auth, health, internal)
- Add authentication middleware for internal pages
- Add database connection utilities
- Implement health check endpoint
This commit is contained in:
Bastian Masanek
2025-10-30 14:28:48 +01:00
parent ef9845c5c5
commit a0121016b9
2 changed files with 87 additions and 0 deletions

34
server/utils/db.ts Normal file
View File

@@ -0,0 +1,34 @@
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import * as schema from '../database/schema'
/**
* Database connection utility
*
* Creates a singleton Drizzle ORM instance with the complete schema.
* This allows for type-safe database queries throughout the application.
*
* Usage:
* ```typescript
* import { db } from '~/server/utils/db'
*
* // Query with relations
* const users = await db.query.users.findMany({
* with: { orders: true }
* })
*
* // Raw SQL with type safety
* import { users } from '~/server/database/schema'
* import { eq } from 'drizzle-orm'
*
* const user = await db.select().from(users).where(eq(users.id, userId))
* ```
*/
const config = useRuntimeConfig()
// Create postgres.js client
const client = postgres(config.databaseUrl)
// Create Drizzle ORM instance with schema
export const db = drizzle(client, { schema })