NestJS - How to access post body using @Body() decorator?
Kamil Mysliwiec's comment about Content-Type
was the solution.
Also, keep in mind to set
Content-Type
request header intoapplication/json
.
In case anyone stumbles on my problem.I had this issue too, but for me was it in the server setup in the main.ts
.
I set this code to include a ssl certificate to work with https, but only in production
let serverOptions = null;if (environment.production) { const httpsOptions = { key: fs.readFileSync(environment.sslKeyPath), cert: fs.readFileSync(environment.sslCertPath), }; serverOptions = { httpsOptions };}const app = await NestFactory.create(AppModule, serverOptions)
but apparently creating a server with options null
, will break it.
So I changed it to something like this, since it works with undefined
const app = await NestFactory.create(AppModule, serverOptions ?? undefinded)
alternatively do something like this, cause I don't know if setting the options to undefined is safe
const app = serverOptions ? await NestFactory.create(AppModule, serverOptions) : await NestFactory.create(AppModule)
Hope this helps someone with a similar problem