Prerequisites
Fastify version
4.x.x
Plugin version
2.3.0
Node.js version
16.18.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
Ventura 13.0
Description
Every express middleware (regardless of being an app, router, middleware, or route) mounted inside a fastify plugin isn't working and returns 404. I've added encapsulation tests to mimic the application.test.js file, and the only test passing is: Should not expose the express app on the root fastify instance when registered inside a plugin.
To make this clearer, this is not working:
fastify.register(expressPlugin).after(function () {
fastify.register(function (instance, opts, done) {
const express = Express()
express.use(function (req, res, next) {
res.setHeader('x-custom', true)
next()
})
express.get('/hello', (req, res) => {
res.status(201)
res.json({ hello: 'world' })
})
instance.use(express)
done()
})
})
Steps to Reproduce
Clone https://github.com/fox1t/fastify-express and run npm i && npm run test:unit ./test/encapsulation.test.js
Expected Behavior
As far as the docs say, it should be possible to add express apps, routers, middleware, and routes inside a plugin. Ref: https://github.com/fox1t/fastify-express#encapsulation-support
Prerequisites
Fastify version
4.x.x
Plugin version
2.3.0
Node.js version
16.18.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
Ventura 13.0
Description
Every express middleware (regardless of being an app, router, middleware, or route) mounted inside a fastify plugin isn't working and returns 404. I've added encapsulation tests to mimic the
application.test.jsfile, and the only test passing is:Should not expose the express app on the root fastify instance when registered inside a plugin.To make this clearer, this is not working:
Steps to Reproduce
Clone https://github.com/fox1t/fastify-express and run
npm i && npm run test:unit ./test/encapsulation.test.jsExpected Behavior
As far as the docs say, it should be possible to add express apps, routers, middleware, and routes inside a plugin. Ref: https://github.com/fox1t/fastify-express#encapsulation-support