H
Hono5d ago
sizzF

Why Are My Hono RPC Routes Not Showing Beyond $get, $post, and $url?

I have set up RPC in my Hono project and configured my routes as follows. However, when I check the available RPC methods, only $get, $post, and $url appear in the list.
How can I make all the other defined routes accessible through RPC? Here is my current router setup:
export const evaluationRoundRouter = new Hono()
.use('/*', isLoggedIn)
.get('/', zValidator('query', selectListEvaluationRoundParamsSchema, validationErrorHook), async c => {
const path = c.req.path;
const params = c.req.valid('query');


const result = await evaluationRoundService.selectList(params);


const response = ResponseCreator.success(
ResponseCreator.list(
result.rows,
result.count,
params.offset && Math.floor(params.offset / (params.limit || 10)) + 1,
params.limit
),
ResponseType.LIST,
{ query: params }
);
return c.json(response);
})
.get('/id/:id',
zValidator('param', selectInfoEvaluationRoundParamsSchema, validationErrorHook),
async c => {
const path = c.req.path;
const params = c.req.valid('param');


const result = await evaluationRoundService.selectInfoById(params);


const response = ResponseCreator.success(
result,
ResponseType.INFO,
{ param: params }
);
return c.json(response);
}
);

const app = new Hono().route('/evaluation/evaluation-round', evaluationRoundRouter);
export const evaluationRoundRouter = new Hono()
.use('/*', isLoggedIn)
.get('/', zValidator('query', selectListEvaluationRoundParamsSchema, validationErrorHook), async c => {
const path = c.req.path;
const params = c.req.valid('query');


const result = await evaluationRoundService.selectList(params);


const response = ResponseCreator.success(
ResponseCreator.list(
result.rows,
result.count,
params.offset && Math.floor(params.offset / (params.limit || 10)) + 1,
params.limit
),
ResponseType.LIST,
{ query: params }
);
return c.json(response);
})
.get('/id/:id',
zValidator('param', selectInfoEvaluationRoundParamsSchema, validationErrorHook),
async c => {
const path = c.req.path;
const params = c.req.valid('param');


const result = await evaluationRoundService.selectInfoById(params);


const response = ResponseCreator.success(
result,
ResponseType.INFO,
{ param: params }
);
return c.json(response);
}
);

const app = new Hono().route('/evaluation/evaluation-round', evaluationRoundRouter);
When I inspect the registered routes using:
app.all().routes.map(v => v.path)
app.all().routes.map(v => v.path)
I can see that all routes are correctly registered:
"/evaluation/evaluation-round",
"/evaluation/evaluation-round/id/:id",
"/evaluation/evaluation-round",
"/evaluation/evaluation-round/id/:id",
Despite this, only $get, $post, and $url appear in the available RPC method list.
How can I make all my defined routes accessible via RPC?
No description
4 Replies
sizzF
sizzFOP5d ago
It seems that .use('/*', isLoggedIn) is causing the issue. Would it be better to apply the middleware to each router separately?
ambergristle
ambergristle5d ago
hey! what methods would you expect to have available? the only one you have registered in the snippet you shared above is GET i would definitely recommend using * instead of /* i assume isLoggedIn is just middleware?
2t8d0s1p
2t8d0s1p15h ago
may I ask why you're calling it like this with the rpc?
No description
2t8d0s1p
2t8d0s1p15h ago
shouldn't it be directly accessible via
const test = await client.api.evaluation.evaluation_round.id[":id"].$get()
const test = await client.api.evaluation.evaluation_round.id[":id"].$get()

Did you find this page helpful?