First Commit Test
This commit is contained in:
13
server/api/examples.get.ts
Normal file
13
server/api/examples.get.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Fetch all `examples` from the database. Run `npx prisma db push` at least once for this to work.
|
||||
*
|
||||
* If you are using `tRPC` you can access the prisma-client by adding it to the context:
|
||||
* ```ts
|
||||
* export async function createContext(event: H3Event) {
|
||||
* return { prisma: event.context.prisma }
|
||||
* }
|
||||
*
|
||||
* export type Context = inferAsyncReturnType<typeof createContext>
|
||||
* ```
|
||||
*/
|
||||
export default defineEventHandler(event => event.context.prisma.example.findMany())
|
||||
9
server/api/trpc/[trpc].ts
Normal file
9
server/api/trpc/[trpc].ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { createNuxtApiHandler } from 'trpc-nuxt'
|
||||
import { appRouter } from '~/server/trpc/routers'
|
||||
import { createContext } from '~/server/trpc/context'
|
||||
|
||||
// export API handler
|
||||
export default createNuxtApiHandler({
|
||||
router: appRouter,
|
||||
createContext
|
||||
})
|
||||
Reference in New Issue
Block a user