mirror of
https://github.com/ArthurDanjou/website.git
synced 2026-01-24 17:00:31 +01:00
first commit
This commit is contained in:
8
src/server/api/trpc/[trpc].ts
Normal file
8
src/server/api/trpc/[trpc].ts
Normal 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
11
src/server/prisma.ts
Normal 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
|
||||
11
src/server/trpc/context.ts
Normal file
11
src/server/trpc/context.ts
Normal 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>
|
||||
7
src/server/trpc/routers/index.ts
Normal file
7
src/server/trpc/routers/index.ts
Normal 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
12
src/server/trpc/trpc.ts
Normal 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
|
||||
Reference in New Issue
Block a user