Giter Site home page Giter Site logo

Comments (2)

B4nan avatar B4nan commented on September 2, 2024

side note: if you say "all latest" in the versions part, you are doing it very wrong. you should put the exact versions you are using. how can i know what does latest mean? latest master? latest 4.x version? latest stable? and if i release new version tomorrow, will that mean it was latest stable yesterday?

it needs to be exact versions, so we get the same information even when we get to the issue in several months.

anyway, you already created the very same issue, this is duplicate of #46, the error in v4 was different, but with the same cause. i will keep this one as here we actually have proper reproduction.

from nestjs.

oznakn avatar oznakn commented on September 2, 2024

Hello,

Apparently, Node's querystring package loses the AsyncResource context while parsing the POST data. NestJS uses fastify-formbody package under the hood, and that one uses Node's querystring package. While the POST data is being parsed, the AsyncResource context has been lost.

Here is a simple patch that I wrote to overcome this problem.

import { AsyncResource } from 'async_hooks';
import { HttpAdapterHost } from '@nestjs/core';

import type { FastifyAdapter } from '@nestjs/platform-fastify';

export class AppModule {
  constructor(adapterHost: HttpAdapterHost<FastifyAdapter>) {
    adapterHost.httpAdapter?.getInstance()
      .addHook('onRequest', (req, _res, done) => {
        req.ctx = new AsyncResource('FastifyNestJSMikroORM');
        done();
      })
      .addHook('preValidation', (req, _res, done) => {
        req.ctx.runInAsyncScope(done);
      });
  }
}

Although this is not something related to MikroORM, I thought that sharing a simple solution for the problem can be something useful.

from nestjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.