作者:WINGZERO哥哥 | 来源:互联网 | 2022-12-02 18:36
nestjs如何在请求中获取COOKIE?
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
}
}
Kamil Myśliw..
11
您必须安装COOKIE-parser
中间件。
$ npm install --save COOKIE-parser
安装过程完成后,只需将中间件绑定到您的应用程序即可:
const app = await NestFactory.create(ApplicationModule);
app.use(COOKIEParser());
在此处阅读更多信息:https : //expressjs.com/en/resources/middleware/COOKIE-parser.html
1> Kamil Myśliw..:
您必须安装COOKIE-parser
中间件。
$ npm install --save COOKIE-parser
安装过程完成后,只需将中间件绑定到您的应用程序即可:
const app = await NestFactory.create(ApplicationModule);
app.use(COOKIEParser());
在此处阅读更多信息:https : //expressjs.com/en/resources/middleware/COOKIE-parser.html