Code Monkey home page Code Monkey logo

Comments (1)

medv avatar medv commented on June 20, 2024
  1. You should include TRPCModule.forRoot in your app module as shown in the example.
  2. Take init-trpc and put it somewhere central. You should export type Router = typeof appRouter here (this is missing in the example but it is assumed you understand this, as it is the main requirement of tRPC that is covered in their great documentation.)
  3. Write your router with procedures in init-trpc, in each procedure you can resolve any service class you wish that has the actual business logic you route to (as shown with ctx.resolveNestDependency(AService)). This particular step is why this adapter exists, to allow you to use nest's dependency injection in your routes.
  4. At some point, you can start breaking out of init-trpc via providing a list of routes in each of your modules (eg. user/user.routes.ts), then importing them all back up to the init-trpc level where you actually create the router out of all of them (you can use tRPC.mergeRouters or nest them in namespaces, see tRPC docs). The main requirement of tRPC is that you combine all your routes into a router and export its type for your front-end to use. When you import the type of the router only, your front end does not include any server side code in the bundle, as typescript types get stripped.
  5. If you are not familiar with the intricacies of modules and bundlers, I would recommend putting some very loud console.logs in your server code, to make sure they never show up anywhere in your client's runtime (in terminal, nor in the browser) so that you can be sure you're not baking in your database secrets or anything of the sort.

from trpc-nestjs-adapter.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.