Korny
Korny
HHono
Created by Korny on 5/8/2024 in #help
Any way to modify the request path in middleware?
(this is cross-posted on https://github.com/orgs/honojs/discussions/2642 - I'm not quite sure which forum we are meant to use? trying both, apologies for the noise) I am trying to replicate a legacy API which had optional versions in paths, so GET /v1/foo actually called GET /foo under the covers. I was hoping to add some middleware that just intercepted paths starting with /v1 and removed the prefix (or re-directed somehow to the correct route) - but it seems that modifying the ctx.req.path does nothing. Is this possible? I've seen examples that clone ctx.req.raw and make a brand new request - that feels a bit ugly, and I'm not sure that Hono will use the new request's path for routing anyway. Any suggestions? (for added complexity we are using the zod-openapi middleware so I can't just give our routes both /foo and /v1/foo paths easily. And we'd like to decrement the /v1 rubbish anyway, so I'd prefer to not have it in our openapi schema)
6 replies
HHono
Created by Korny on 4/17/2024 in #help
Case insensitive query params
We are using hono-zod-openapi to replace an existing API. Sadly the old API (written in ASP.Net) appears to have case-insensitive handling of parameters - and we may need to emulate this. Gah. So we have something like
const myParams = z.object({
FooBar: z.string().openapi({...})
});
const route = createRoute({
method: 'get',
path: '/blah',
request:{
query: myParams,
const myParams = z.object({
FooBar: z.string().openapi({...})
});
const route = createRoute({
method: 'get',
path: '/blah',
request:{
query: myParams,
But I need to support GET /blah?fooBar= and all other variants of FooBar and foobar etc. Any ideas? I guess worst case we could add some middleware to downcase all parameters or something.
2 replies