Son
Son3y ago

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,
})
);
8 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Alex / KATT 🐱
GitHub
GitHub - rhenriquez28/trpc-client-devtools: An unofficial browser e...
An unofficial browser extension for inspecting queries, mutations and subscriptions in your tRPC app - GitHub - rhenriquez28/trpc-client-devtools: An unofficial browser extension for inspecting que...
Alex / KATT 🐱
GitHub
GitHub - sachinraja/trpc-playground: playground for running tRPC qu...
playground for running tRPC queries in the browser - GitHub - sachinraja/trpc-playground: playground for running tRPC queries in the browser
kumard3
kumard33y ago
So with this can i access my trpc endpoints on different webisite by making and api request?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
kumard3
kumard33y ago
that is what i want , thank you man , one more question do you have any example of trpc-openapi prisma example ?😅
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View