Skip to content

Express compatibility #1503

@delvedor

Description

@delvedor

🚀 Feature Proposal

From the next version of Fastify, I would love to decouple even more Express middlewares from the core framework.
The current solution is to integrate Middie with Fastify and expose it via the use API.
I think we should design a new plugin that offers this functionality (and at the same time remove the use API from core); technically is possible since Fastify offers everything we might need to achieve this goal.
Moreover, if we expose this functionality as a plugin, we could even improve the Express support, and apply many other modifications to the request object that we are currently not doing in core to avoid a performance hit.
Finally, we will remove the confusion generated by hooks vs middlewares.

Motivation

  • Discourage the use of Middlewares and encourage the use of our Hooks.
  • Drop an API from core that does not need to be there, and increases the internal complexity.
  • Improved Express compatibility.
  • Performances++ if you don't need Express compatibility.

Example

const fastify = require('fastify')()
fastify
  .register(require('fastify-express'))
  .after(() => {
    fastify.use(require('express-stuff'))
  })
  .listen(3000)

What do you think?
What can we put inside this plugin to improve express compatibility?
Any feedback is welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionIssues or PRs with this label will never stalesemver-majorIssue or PR that should land as semver majorv3.xIssue or pr related to Fastify v3

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions