tRPCttRPC
Powered by
SonS
tRPC•4y 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 });
  }),
});
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();
  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);
  });
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,
    })
  );
  app.use(
    '/getTenantById',
    trpcExpress.createExpressMiddleware({
      router: ticketServiceRouter,
      createContext,
    })
  );
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

TRPC ratelimiting endpoints
rustclanRrustclan / ❓-help
3y ago
Call multiple TRPC endpoints from onSuccess()?
peternovakPpeternovak / ❓-help
3y ago
uploading image via trpc endpoint
PeformPPeform / ❓-help
2y ago