nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.63k stars 7.62k forks source link

POST request is hanged when using Fastify adapter #12867

Closed truongtrongtin closed 11 months ago

truongtrongtin commented 11 months ago

Is there an existing issue for this?

Current behavior

Fastify adapter: POST request is hanged, GET request works fine

let nestApp: NestFastifyApplication;

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(),
  );
  return app.init();
}

export async function api(req: Request, res: Response) {
  nestApp = nestApp ?? (await bootstrap());
  const instance = nestApp.getHttpAdapter().getInstance();
  await instance.ready();
  instance.server.emit('request', req, res);
}

Express adapter works fine

let nestApp: NestExpressApplication;

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(
    AppModule,
    new ExpressAdapter(),
  );
  return app.init();
}

export async function api(req: Request, res: Response) {
  nestApp = nestApp ?? (await bootstrap());
  const instance = nestApp.getHttpAdapter().getInstance();
  instance(req, res);
}

Minimum reproduction code

https://github.com/truongtrongtin/nestjs-function/blob/main/src/main.ts

Steps to reproduce

pnpm install
pnpm run start:dev
curl -X POST http://localhost:8080 -d "name=john"

Expected behavior

Should works

Package

Other package

No response

NestJS version

No response

Packages versions

  "dependencies": {
    "@google-cloud/functions-framework": "^3.3.0",
    "@nestjs/common": "^10.2.10",
    "@nestjs/core": "^10.2.10",
    "@nestjs/platform-express": "^10.2.10",
    "@nestjs/platform-fastify": "^10.2.10",
    "class-validator": "^0.14.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.2.1",
    "@nestjs/schematics": "^10.0.3",
    "@nestjs/testing": "^10.2.10",
    "@types/express": "^4.17.21",
    "@types/jest": "^29.5.10",
    "@types/node": "^20.10.1",
    "@types/supertest": "^2.0.16",
    "@typescript-eslint/eslint-plugin": "^6.13.1",
    "@typescript-eslint/parser": "^6.13.1",
    "env-cmd": "^10.1.0",
    "eslint": "^8.54.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.1",
    "jest": "^29.7.0",
    "prettier": "^3.1.0",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.3",
    "ts-jest": "^29.1.1",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.1",
    "tsc-watch": "^6.0.4",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.3.2"
  },

Node.js version

20.10.0

In which operating systems have you tested?

Other

No response

kamilmysliwiec commented 11 months ago

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.