Comments (10)
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.
from fastify-compress.
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.
from fastify-compress.
I recommend you use the form of
import fastifyCompress from '@fastify/compress`
fastify.register(fastifyCompress, { global: false })
It often the problem of the user do not configure TypeScript
correctly. So, the type merging
is not working.
from fastify-compress.
I may mis-understand the issue. It is not TypeScript related.
You are required to await
the registration for it works.
await fastify.register(require('@fastify/compress'), { global: false })
The reason behind in the fastify migration guide
from fastify-compress.
(async () => {
await fastify.register(require('@fastify/compress'),{threshold: 2048, global: true })
console.log("compress ok");
})();
"compress ok" is printed. But still "reply.compress is not a function"
For curiosity I added console.log() before line 204, in
https://github.com/fastify/fastify-compress/blob/master/index.js#L204
and it is not printed. The reply is used for a http POST method, I do not know if it changes something
from fastify-compress.
By looking at the test, your case should be supported.
fastify-compress/test/routes-compress.test.js
Lines 133 to 158 in 430b4f3
I may expect your application is run into some encapsulated context, so the route and plugin are actually in two different context.
Can you provide a minimal repo that I can actually run?
from fastify-compress.
fastify-compress/test/routes-compress.test.js
Lines 133 to 158 in 430b4f3
and is it possible to add a fastify.post(...)
test case?
from fastify-compress.
is it possible to add a fastify.post(...) test case?
I didn't see how .post
is related, but welcome to add one.
from fastify-compress.
is it possible to add a fastify.post(...) test case?
I didn't see how
.post
is related, but welcome to add one.
I don't get the point, why it is not working using commonjs? isn't cjs supported anymore?
from fastify-compress.
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 notawait
that file in the most upper layer.
Thank you so much! Exactly that. Now I get it, it was not the "right fastify object" the one I attached the route, and that means the better way to make compress works with commonjs is to wrap all in a async start function
from fastify-compress.
Related Issues (20)
- replace deprecated node-zlib HOT 2
- Duplicated accept-encoding vary header in response HOT 2
- Add to docs info that "fastify-compress" MUST be registered BEFORE "fastify-static". HOT 2
- Add ability to append 'vary' response header rather than create a new one HOT 4
- More than one wildcard directive in accept-encoding header causes fall back to `br` not `gzip` HOT 1
- 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
- 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
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.