Giter Club home page Giter Club logo

Comments (6)

kartikk221 avatar kartikk221 commented on September 22, 2024

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.

o-az avatar o-az commented on September 22, 2024

@kartikk221

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)

CleanShot 2023-11-21 at 19 36 08@2x

from hyper-express.

kartikk221 avatar kartikk221 commented on September 22, 2024

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.

o-az avatar o-az commented on September 22, 2024

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.

kartikk221 avatar kartikk221 commented on September 22, 2024

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.

Geo25rey avatar Geo25rey commented on September 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.