How encapsulation works with @fastify/express
mainThe plugin respects Fastify's encapsulation model. You can:
- Register the plugin in a subsystem: Express middleware will only be available within that specific plugin scope.
- Register middleware in a nested plugin: If
@fastify/expressis registered at the top level, middleware registered inside a nested plugin will only execute for routes within that plugin's scope.
// Example: Registering middleware in a specific plugin scope
const fastify = require('fastify')()
fastify
.register(require('@fastify/express'))
.register(subsystem)
async function subsystem (fastify, opts) {
// This middleware only applies to routes inside 'subsystem'
fastify.use(require('cors')())
}