How does nestjs get the cookie in the request?
import { Get, Controller, Response, Request } from '@nestjs/common';
import { AppService } from './app.service';
const l = console.log
@Controller()
export class AppController {
@Get('json')
json(@Request() req){
console.log(req.cookies) // undefined
}
}
You have to install cookie-parser
middleware.
$ npm install --save cookie-parser
once the installation process is completed, simply bind middleware to your application:
const app = await NestFactory.create(ApplicationModule);
app.use(cookieParser());
read more here: https://expressjs.com/en/resources/middleware/cookie-parser.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With