/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/minimal-react/server/index.ts
47 строк
1 KB
Julius Marminge
chore: next merge 2023 03 05 (#3926)
06 мар 2023, 15:44
Не верифицирован
06 мар 2023, 15:44
98d2d02
Код
Авторство
О чём код?
/** * This is the API-handler of your app that contains all your API routes. * On a bigger app, you will probably want to split this file up into multiple files. */ import { initTRPC } from '@trpc/server'; import { createHTTPServer } from '@trpc/server/adapters/standalone'; import cors from 'cors'; import { z } from 'zod'; const t = initTRPC.create(); const publicProcedure = t.procedure; const router = t.router; const appRouter = router({ greeting: publicProcedure // This is the input schema of your procedure // 💡 Tip: Try changing this and see type errors on the client straight away .input( z .object({ name: z.string().nullish(), }) .nullish(), ) .query(({ input }) => { // This is what you're returning to your client return { text: `hello ${input?.name ?? 'world'}`, // 💡 Tip: Try adding a new property here and see it propagate to the client straight-away }; }), }); // export only the type definition of the API // None of the actual implementation is exposed to the client export type AppRouter = typeof appRouter; // create server createHTTPServer({ middleware: cors(), router: appRouter, createContext() { console.log('context 3'); return {}; }, }).listen(2022);