Prerequisites
Fastify version
4.12.0
Plugin version
5.7.1
Node.js version
v18.12.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Ubuntu 22.04.1 LTS
Description
When starting the app it seems that indexPattern is ignored and all plugins are loaded also for appV1Private that has a different pattern regex.
Any idea?
Steps to Reproduce
These are the relevant parts of the code
Main server, two Fastify instances. Each instance with own routes and own port.
...
const server = fastify({})
const serverPrivate = fastify({})
...
server.register(appV1, { prefix: '/api/v1' })
serverPrivate.register(appV1Private, {prefix: '/api-private/v1'})
...
// public
server.listen({ port: 8443 }, (err, address) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log(`Public Server listening ${address}`)
})
// private
serverPrivate.listen({ port: 9443 }, (err, address) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log(`Private server listening ${address}`)
})
appV1
This should load only plugins with files like module.ts, right?
import { FastifyPluginCallback, HTTPMethods } from 'fastify'
import { join } from 'path'
import fastifyAutoload from '@fastify/autoload'
import logger from '@root/utils/log';
const app: FastifyPluginCallback = function (fastify, opts, next): void {
/** AUTOLOAD PLUGINS */
fastify.register(fastifyAutoload, {
dir: join(__dirname, 'plugins'),
dirNameRoutePrefix: false,
indexPattern: /.*module(\.ts|\.js|\.cjs|\.mjs)$/,
maxDepth: 1,
encapsulate: false,
logLevel: 'info',
})
next()
}
export default app;
appV1Private
This should load only plugins with files like modulePrivate.ts, right?
import { FastifyPluginCallback, HTTPMethods } from 'fastify'
import { join } from 'path'
import fastifyAutoload from '@fastify/autoload'
import logger from '@root/utils/log';
const app: FastifyPluginCallback = function (fastify, opts, next): void {
/** AUTOLOAD PLUGINS */
fastify.register(fastifyAutoload, {
dir: join(__dirname, 'plugins'),
dirNameRoutePrefix: false,
indexPattern: /.*modulePrivate(\.ts|\.js|\.cjs|\.mjs)$/,
maxDepth: 1,
encapsulate: false,
logLevel: 'info',
})
next()
}
export default app;
Inside plugins there are many Fastify plugins BUT only in one there is a file named modulePrivate.ts
When starting the app it seems that indexPattern is ignored and all plugins are loaded also for appV1Private
Any idea?
Expected Behavior
appV1 should load only plugins with module.ts inside
appV1Private should load only plugins with modulePrivate.ts inside.
Prerequisites
Fastify version
4.12.0
Plugin version
5.7.1
Node.js version
v18.12.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Ubuntu 22.04.1 LTS
Description
When starting the app it seems that
indexPatternis ignored and all plugins are loaded also forappV1Privatethat has a different pattern regex.Any idea?
Steps to Reproduce
These are the relevant parts of the code
Main server, two Fastify instances. Each instance with own routes and own port.
appV1
This should load only plugins with files like
module.ts, right?appV1Private
This should load only plugins with files like
modulePrivate.ts, right?Inside plugins there are many Fastify plugins BUT only in one there is a file named
modulePrivate.tsWhen starting the app it seems that
indexPatternis ignored and all plugins are loaded also forappV1PrivateAny idea?
Expected Behavior
appV1should load only plugins withmodule.tsinsideappV1Privateshould load only plugins withmodulePrivate.tsinside.