Closed vitalikprac closed 2 years ago
Thanks for reporting.
We changed the default behavior in V4, promoting a good promise hygiene.
Your promise returns undefined
, so that's what you get.
fastify.get('/', async(request, reply) => {
return 'hello world'
})
or
fastify.get('/', async(request, reply) => {
reply.send('hello world')
return reply
})
Thanks, it's work for me. Also would be nice if you add example with async function to README for better developers experience.
Prerequisites
Fastify version
4.2.0
Plugin version
6.1.0
Node.js version
16.15.0
Operating system
Windows 11
Browser
Chrome 102
Description
The route of fastify has handler function and it's work as expected.
Browser show the correct response headers and render 'hello world' to html
But if we changed handler function to async, it has strange behaviour
In browser, response headers displays
content-length: 0
And browser says that request has no response data availableIf I understand correctly https://github.com/fastify/fastify-compress/issues/140 issue should resolve my problem , but it would not work for me.
Steps to Reproduce
fastify
and@fastify/compress
server.js
fileconst fastify = Fastify(); await fastify.register(FastifyCompress, { threshold: 0 }); fastify.get('/', async(request, reply) => { reply.send('hello world'); }) await fastify.listen({ port: 3000 })
Expected Behavior
Browser should render
hello world
in async fastify handler as it does in non-async handler