Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does nestjs get the cookie in the request?

Tags:

nestjs

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
  }
}
like image 502
januw a Avatar asked Oct 08 '18 15:10

januw a


1 Answers

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

like image 123
Kamil Myśliwiec Avatar answered Sep 28 '22 03:09

Kamil Myśliwiec