Hi, I have main.ts setup like this to deploy it on google cloud function
import { Request, Response } from '@google-cloud/functions-framework';
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
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);
}
The problem is when I call a POST request, the request is not processed:
curl -X POST http://localhost:8080 -d "name=john"
Though calling a GET request like this works fine
curl http://localhost:8080
I wonder if my setup is not correct. I tried to use @nestjs/platform-express and it works fine also
Minimum reproduction code:
https://github.com/truongtrongtin/nestjs-function/blob/main/src/main.ts