Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fastify] Crash when registering a middleware that also registers middie #13729

Closed
1 task done
ancyrweb opened this issue Jun 30, 2024 · 3 comments
Closed
1 task done
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@ancyrweb
Copy link

ancyrweb commented Jun 30, 2024

Is there an existing issue that is already proposing this?

  • 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.

Repro

Here's a sample project that illustrates the problem : https://github.com/ancyrweb/nestjs-react-vite-ssr
Remove the line (adapter as any).isMiddieRegistered = true; in the src/main.ts file.

@ancyrweb ancyrweb added needs triage This issue has not been looked into type: enhancement 🐺 labels Jun 30, 2024
@micalevisk
Copy link
Member

Please provide a minimum reproduction repository. You can start one by running npm init nest in your terminal

why reproductions are required

@ancyrweb
Copy link
Author

ancyrweb commented Jul 1, 2024

@micalevisk updated

@kamilmysliwiec
Copy link
Member

Feel free to create a PR that allows passing the skipMiddie attribute to the FastifyAdapter constructor (as part of the options object)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

3 participants