SonS
tRPC4y ago
8 replies
Son

cant access trpc endpoints via the browser

i'm converting some express endpoints to trpc, and I cant figure out how to access my endpoints via the browser for example http://localhost:3000/trpc/getbytenantid

my trpc endpoint

export const ticketServiceRouter = router({
  getByTenantId: ticketServiceProcedure.query(async () => {
    const repo = createRepo();
    const tenantId = '908e2d94-aef7-4ba6-a1a3-2ccec65a1d97';

    return await repo.get_by_tenant_id({ tenantId });
  }),
});

i get my data in the frontend no problem.

  const tickets = trpc.ticketService.getByTenantId.useQuery();


my express endpoint

export const create = (router: Router) => {
  const repo = createRepo();

  router.get('/tickets/get_by_tenant_id', async (req, res) => {
    // Mocked. Should be extracted from the JWT.
    const tenantId = '908e2d94-aef7-4ba6-a1a3-2ccec65a1d97';

    const result = await repo.get_by_tenant_id({ tenantId });

    res.json(result);
  });


express adapter

  app.use(
    '/getTenantById',
    trpcExpress.createExpressMiddleware({
      router: ticketServiceRouter,
      createContext,
    })
  );
Was this page helpful?