export class LoggerMiddleware implements NestMiddleware { use(req: Request, res: Response, next: () => void) { const code = res.statusCode; // 响应状态码 next(); // 组装日志信息 const logFormat = `方法:${req.method} \n Request original url:${req.originalUrl} \n 状态码:${code} ...
:boolean;/** * Function to set custom headers on response. Alterations to the headers need to occur synchronously. * The function is called as fn(res, path, stat), where the arguments are: * res the response object * path the file path that is being sent * stat the stat object of ...
throw new HttpException('Forbidden', HttpStatus.FORBIDDEN); // 方式2:直接抛出HttpException,异常信息为object throw new HttpException({ status: HttpStatus.FORBIDDEN, error: 'This is a custom message', }, HttpStatus.FORBIDDEN); // 方式3:抛出HttpException子类(内置异常/自定义异常) throw new UnAuthent...
getAllUsers(@Response() res) { return this.usersService.getAllUsers() } @Get('/:id') getUser(@Response() res, @Param('id') id) { return this.usersService.getUser(+id) } @Post() addUser(@Response() res, @Body('user') user) { return this.usersService.addUser(user) } } use...
ArgumentsHost在NestJs中用来提供处理器(handler)的参数,例如在使用Express平台(@nestjs/platform-express)时,ArgumentsHost就是一个数组,包含Express中的[request,response,next],前两个作为对象(Object)而最后一个作为函数。在其他使用场景中,例如GraphQL时,ArguimentsHost则表示[root,args,context,info]数组。在Nest...
import { CustomError } from '@app/errors/custom.error'; import { ResponseStatus } from'@app/interfaces/response.interface'; import { ValidationError, ValidationPipe, ValidationPipeOptions, HttpStatus } from'@nestjs/common'; import { HttpErrorByCode } from'@nestjs/common/utils/http-error-by-cod...
User Response Classes import { Exclude } from 'class-transformer'; export class UserResponse { id: number; username: string; @Exclude() roles: string; @Exclude() password: string; @Exclude() profileId: number; constructor(partial: Partial<UserResponse>) { Object.assign(this, partial); } }...
* Function to set custom headers on response. Alterations to the headers need to occur synchronously. * The function is called as fn(res, path, stat), where the arguments are: * res the response object * path the file path that is being sent ...
SNMP(Simple Network Management Protocol)是一种用于管理和监控网络设备的协议。它允许网络管理员通过远程...
the maxAge option to check if the file has changed. */ immutable?: boolean;/** * By default this module will send "index.html" files in response to a request on a directory.* To disable this set false or to supply a new index pass a string or an array in preferred order.