Open revosw opened 2 years ago
Thank you for pointing that out. Would you please create a failing test case I can use to implement a fix? Otherwise I'll do it.
I'm sorry but I didn't commit the code before migrating to typebox, so the state of the project when I made that code is gone. I sadly don't have the energy to set up a minimal repro
Is this going anywhere? Also the case for fastify-autoload
plugin: #34
this makes the fastify.zod[get|post|etc]
is completely incompatible with my setup and i'll have to continue the "deprecated" route..
I am very interested in supporting this. Can you please provide me with some example code?
@elierotenberg so for context, a lot of people structure their routes like this with fastify:
app.register((i, r, d) => {
i.register(hotTakesRoutes, {
prefix: 'hot-takes'
})
done()
}, {
prefix: 'api',
})
this is super handy since you can inject different stuff into the request depending on the request group - they all share the prefix, you can add extra guards etc
it's explained in more detail here: https://www.fastify.io/docs/latest/Reference/Plugins/
moreover a lot of people also prefer the instance.route()
way of defining routes.. ie.
instance.route<{ Reply: SomeDef }>({
method: 'GET',
url: '/someurl',
preHandler: (req) => { /* check something, or query for data */ },
handler: async () => {
...route logic
}
})
I'm not here to argue for why somebody would do this, this is just part of the fastify api. and the reason why the very nice and clever looking api instance.zod.xxx()
won't work for a lot of fastify use cases.
I hope that clarifies the issue and is helpful
Is there a way I can help with this issue? Sample github project or something?
Is there any news on this?
In a setup I have, I make a subroute under
/admin/:id
. The normalinstance.get()
method in the subroute recognizes that the prefix has been added, so/ventilator
is appended to/admin/:id
. However,instance.zod.get()
does not recognize the prefix, and insists that I have to assign/admin/:id/ventilator
as the path.