question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reply.compress is not working as expected

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.9.2

Plugin version

6.1.1

Node.js version

18.10.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Alpine Linux 3.16 with node 18

Description

as documented, I registered the plugin with code:

fastify.register(require('@fastify/compress'),{global: false })

then tried to use reply.compress() I have this error (and crash):

/home/node/code/models/stream-result.js:46
      reply.type('application/json').compress(piped);
                                     ^

TypeError: reply.type(...).compress is not a function

piped is a stream, and replacing with compress with send works

Steps to Reproduce

not sure if it is needed to pass reply object to an external function to reproduce the error

Expected Behavior

It should accept a stream and stream it.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
climba03003commented, Oct 20, 2022

and that means the better way to make compress works with commonjs is to wrap all in a async start function

I always recommend people to put all the routes inside a plugin. So, they will not face similar issue. I do not recommend to place fastify.get or similar in the same level of fastify.register.

For example,


fastify.register(plugin, {})

fastify.get('/', function() {})

should refactor into


fastify.register(plugin, {})

fastify.register(function(fastify, __, done) {
  fastify.get('/', function() {})

  done()
})

In this case, wrapper of async start is not needed.

1reaction
climba03003commented, Oct 20, 2022

I don’t get the point, why it is not working using commonjs? isn’t cjs supported anymore?

It is supported in commonjs. And I have no idea why it didn’t works for you without a minimal repo.

My guess is about there are something wrong about your setup. For example, the routes and @fastify/compress are inside separate encapsulation context.

Another though is all the plugin is registered inside the same file. And you did not await that file in the most upper layer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Response compression in asp.net core 2.2 not working
UseResponseCompression() to the top of the method. I validated it and found working fine as expected. public void Configure(IApplicationBuilder ...
Read more >
Premature close · Issue #215 · fastify/fastify-compress - GitHub
This appears to happen when request is aborted while still serving the file. Expected Behavior. Should produce a warning, but not an uncaught ......
Read more >
5.0 zstd compression level is not working as expected
Hi @Aayushi_Mangal. Compression performance depends very much on the documents. If the document contains a random string pattern, ...
Read more >
Troubleshooting IIS Compression issues in IIS6/IIS7.x
Enable Compression in IIS6/IIS7: From the IIS Manager, right-click on the Web Sites node, Properties and click on Services. Screenshot of ...
Read more >
ASP.NET Response Compression - wolfSYS.net
Compression is a simple and effective way to save bandwidth and speed up your site. Here we'll cover both classic ASP.NET MVC and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found