Comments (2)
If you have an async handler, you should always return the body instead of using reply.send
:
const fastify = new Fastify({})
fastify.register(fastifyCompress) // #1 disable this line will work
fastify.get('/subscription', async (req, reply) => {
const longString = new Array(1024).fill('a').join('') // <--- build a string, whose length is >= 1024 (compress.threshold)
return longString
})
Or:
const fastify = new Fastify({})
fastify.register(fastifyCompress) // #1 disable this line will work
fastify.get('/subscription', (req, reply) => {
const longString = new Array(1024).fill('a').join('') // <--- build a string, whose length is >= 1024 (compress.threshold)
reply.send(longString)
})
You can find more information here: https://fastify.dev/docs/latest/Reference/Routes/#promise-resolution
from fastify-compress.
@gurgunday Thanks for sharing info.
It's a bit tricky for a new user. I'd now strictly call return reply.send(...)
. Syntax sugar is painful when migrating between different frameworks.
I was not aware this when migrating from Koa of promise based routes.
// in koa
async someGetRoute(ctx) {
ctx.body = await getMyDataAsync()
}
// in fastify
async someGetRoute(request, reply) {
return reply.send(await getMyDataAsync())
}
from fastify-compress.
Related Issues (20)
- fastify decompress using preParsing hook HOT 2
- Conditionally Enable Content-Length Header HOT 12
- feat: move to `compress` and `decompress` route specific options, improved typescript types and tests, reorganize tests HOT 1
- Unexepected/unwanted behavior with zip payloads
- Premature close HOT 41
- ChainAlert: npm package release (4.1.0) has no matching tag in this repo
- [Fastify-compress] Not working with aws api gateway proxy+ HOT 3
- Empty reply data in Fastify async route HOT 2
- [feature] Add flush method HOT 5
- reply.compress is not working as expected HOT 10
- Regarding content encoding priorities in fastify/compress HOT 5
- The response is not getting compressed when sending accept-encoding as gzip? HOT 1
- please create the missing 4.1.0 tag HOT 2
- How to cache the compressed responses? HOT 2
- Accept-Encoding should not be added to 'Vary' for non-compressable Content-Types HOT 4
- 7.0.1 changes the brotli default quality HOT 3
- Unicode emoji converted to broken chars in certain extreme long string responses HOT 24
- Content-Length is not included in repsonse header, even when removeContentLengthHeader is false HOT 3
- Difficulty optimizing dependencies for AWS Lambda HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-compress.