New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding type for fastify.routing #3270
adding type for fastify.routing #3270
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test for those types? We use tsd
.
@mcollina Thanks for reviewing this PR. I just added a simple test, please take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance, no problem. But I never use this method, I cannot confirm if the type is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: I was unable to find a test for this method in the test/
folder.
This snippet just let the server crash (I think it creates an infinite loop)
const fastify = require('fastify')({ logger: true })
fastify.get('/', async (request, reply) => {
fastify.routing(request.raw, reply.raw)
return { hello: 'world' }
})
fastify.listen(8080)
@Eomm Yes, it is created an infinite loop. This method found the handler and it will execute the handler. When you use it inside the |
Hi @Eomm, I think this instance method is for handling requests from other instance or HTTP server. e.g.: const naviteHttpServer = http.createServer((req, res) => {
fastify.routing(req, res)
}) this is my use case at least, https://github.com/axe-me/vite-plugin-node/blob/main/src/server/fastify.ts#L8 This method is quite useful for passing raw requests from another frameworks like express/koa to fastify programmatically without using a HTTP proxy. cc @climba03003 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing your use case.
We could add a safe-check to avoid this crash, but it is not about your PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
adding missing type declaration for https://www.fastify.io/docs/latest/Server/#routing