first commit

This commit is contained in:
2023-05-02 19:11:53 +02:00
commit a6f058452d
21 changed files with 9977 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import { createNuxtApiHandler } from 'trpc-nuxt'
import { createContext } from '~/server/trpc/context'
import { appRouter } from '~/server/trpc/routers'
export default createNuxtApiHandler({
createContext,
router: appRouter,
})

11
src/server/prisma.ts Normal file
View File

@@ -0,0 +1,11 @@
import { PrismaClient } from '@prisma/client'
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }
export const prisma = globalForPrisma.prisma
|| new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
})
if (process.env.NODE_ENV !== 'production')
globalForPrisma.prisma = prisma

View File

@@ -0,0 +1,11 @@
import type { inferAsyncReturnType } from '@trpc/server'
import type { H3Event } from 'h3'
import { prisma } from '~/server/prisma'
export function createContext(_event: H3Event) {
return {
prisma,
}
}
export type Context = inferAsyncReturnType<typeof createContext>

View File

@@ -0,0 +1,7 @@
import { router } from '~/server/trpc/trpc'
export const appRouter = router({
})
export type AppRouter = typeof appRouter

12
src/server/trpc/trpc.ts Normal file
View File

@@ -0,0 +1,12 @@
import { initTRPC } from '@trpc/server'
import SuperJSON from 'superjson'
import type { Context } from '~/server/trpc/context'
const trpc = initTRPC.context<Context>().create({
transformer: SuperJSON,
})
export const publicProcedure = trpc.procedure
export const router = trpc.router
export const middleware = trpc.middleware
export const mergeRouters = trpc.mergeRouters