nest
nest copied to clipboard
[Fastify] Crash when registering a middleware that also registers middie
Is there an existing issue that is already proposing this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe it
I'm trying to integrate @fastify/vite with NestJS, but both @fastify/vite & @nestjs/platform-fastify register middie.
Which leads to a crash.
So far the solution I've found is to implement the following.
async function bootstrapNestJs() {
const adapter = new FastifyAdapter({ logger: true });
await adapter.register(FastifyVite as any, {
...
});
(adapter as any).isMiddieRegistered = true;
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
adapter,
);
const server = app.getHttpAdapter().getInstance() as any;
await server.vite.ready();
await app.listen(3000);
}
Describe the solution you'd like
The simple patch would be to add an other flag to the FastifyAdapter constructor to mark middie as already registered.
I can propose a PR if wanted.
Teachability, documentation, adoption, migration strategy
It's just an optional flag.
What is the motivation / use case for changing the behavior?
Required to setup Vite with NestJS.