diff --git a/src/pages/index.vue b/src/pages/index.vue index 28cedf8..7698fe7 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -1,9 +1,12 @@ diff --git a/src/plugins/trpc.ts b/src/plugins/trpc.ts index 680d8f9..b88bde5 100644 --- a/src/plugins/trpc.ts +++ b/src/plugins/trpc.ts @@ -1,3 +1,4 @@ +import { loggerLink } from '@trpc/client' import SuperJSON from 'superjson' import { createTRPCNuxtClient, httpBatchLink } from 'trpc-nuxt/client' import type { AppRouter } from '~/server/trpc/routers' @@ -6,6 +7,11 @@ export default defineNuxtPlugin(() => { const trpc = createTRPCNuxtClient({ transformer: SuperJSON, links: [ + loggerLink({ + enabled: opts => + process.env.NODE_ENV === 'development' + || (opts.direction === 'down' && opts.result instanceof Error), + }), httpBatchLink({ url: '/api/trpc', }), diff --git a/src/server/trpc/routers/index.ts b/src/server/trpc/routers/index.ts index c59de5d..ecf71e6 100644 --- a/src/server/trpc/routers/index.ts +++ b/src/server/trpc/routers/index.ts @@ -1,7 +1,16 @@ -import { router } from '~/server/trpc/trpc' +import { z } from 'zod' +import { publicProcedure, router } from '~/server/trpc/trpc' export const appRouter = router({ - + hello: publicProcedure + .input(z.object({ + name: z.string().optional(), + })) + .query(({ input }) => { + return { + greeting: `Hello ${input.name ?? 'world'}!`, + } + }), }) export type AppRouter = typeof appRouter