Comments (6)
Hey, this middleware does not seem to be maintained anymore given by the last publish 5 years ago. I am assuming it is depending on an old compatibility method or behavior from Express. When you use it with hyper-express
, what if any errors / stack traces do you see in the console?
from hyper-express.
import HyperExpress from 'hyper-express'
import compression from 'compression'
const server = new HyperExpress.Server()
function shouldCompress(request: HyperExpress.Request, response: HyperExpress.Response) {
if (request.headers['x-no-compression']) return false
return compression.filter(request, response)
}
server.use((request, response, next) => {
const compress = compression({ filter: shouldCompress })
return compress(request, response, next)
})
server.all('/', (request, response, _) => response.send('Hello World'))
const PORT = Number(process.env.PORT ?? 3034)
server.listen(PORT)
curl http://localhost:3034 --head
# no compression headers
HTTP/1.1 200 OK
Date: Wed, 22 Nov 2023 03:34:49 GMT
Content-Length: 11
Type errors:
compression.filter
request and response arguments types are incompatible with HE request type:
Argument of type 'Request<DefaultRequestLocals>' is not assignable to parameter of type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Type 'Request<DefaultRequestLocals>' is missing the following properties from type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>': accepted, host, route, signedCookies, and 13 more.ts(2379)
from hyper-express.
So is the incompatibility just TypeScript types or is it a functional incompatibility? I notice that you said there are no compression headers added, so the middleware is just not running at all?
from hyper-express.
So is the incompatibility just TypeScript types or is it a functional incompatibility? I notice that you said there are no compression headers added, so the middleware is just not running at all?
Yes not running at all. It seems to have no effects
from hyper-express.
I see, that likely means there is some method / property which is incompatible under the hood. For now, HyperExpress has limited compatibility with Express.js and this would be one of the cases where this middleware is just not compatible. The likely reason is that the middleware is old and not maintained anymore so it likely depends on an older and more obscure property/method from Express that is not supported at the moment.
The next major version update will make some breaking changes to increase the compatibility with Express, so that might resolve your issue in the future but for now this middleware would be incompatible.
from hyper-express.
@o-az Looks like this is not an incompatibility with hyper-express
(besides type errors).
The compression
library seems to require the "Content-Type" header to properly understand if the content is compressible. See the compressible
library for details. Here's excerpt from compressible
's README explaining the filter logic:
The MIME is looked up in the mime-db and if there is compressible information in the database entry, that is returned. Otherwise, this module will fallback to true for the following types:
- text/*
- */*+json
- */*+text
- */*+xml
Word of advice:
Next time you encounter an old Node.JS library you want to use with little documentation (it will happen), look at the source code. They are typically 1 short JS file with decently readable code, especially if they have multiple dependencies.
from hyper-express.
Related Issues (20)
- Response send vs json HOT 8
- `res.cookie` is incompatible with express HOT 1
- A build error appeared with version 6.14.2 with TypeScript types definition HOT 1
- Can't handle error in global error handler
- Default Encoding problems with accents HOT 1
- HI kartik, I'm sorry for the stupid question, but I need to learn how to work with this by example, can you show me?) HOT 3
- Handling multiple multipart HOT 7
- Question: Is there support for HTTP3 / QUIC ? HOT 1
- Feature request: swagger HOT 1
- No error thrown if invalid json is sent as body HOT 4
- From version 6.0.0, the response component doesn´t call a close or abort event when the SSE client is closed HOT 1
- Nest-hyper-express-adapter middleware tests failing HOT 4
- Nest-hyper-express instance and local-pipes tests each fail one test HOT 3
- Outdated example of static serving / LiveDirectory HOT 1
- Error: uWS.HttpResponse must not be accessed after uWS.HttpResponse.onAborted callback HOT 1
- Graceful shutdown HOT 4
- Static serving HOT 1
- No error on binding to the same port HOT 1
- No Socket Received From uWebsockets.js likely due to an invalid host or busy port. HOT 2
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 hyper-express.