小编Faa*_*han的帖子

如何从 Nest fastify 服务器中创建的中间件发送响应?

我用 Fastify 创建了一个 NestJs 项目,并为其创建了一个中间件,但我不知道如何向客户端发送响应,类似于我们在 Express 中的做法,任何帮助将不胜感激,谢谢!,这是我的中间件代码:

import {
  Injectable,
  NestMiddleware,
  HttpException,
  HttpStatus,
} from '@nestjs/common';

@Injectable()
export class LoggerMiddleware implements NestMiddleware {
  use(req: any, res: any, next: Function) {
    console.log('Request...', res);
    // throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
    next();
  }
}
Run Code Online (Sandbox Code Playgroud)

nestjs fastify nestjs-fastify

4
推荐指数
1
解决办法
7399
查看次数

标签 统计

fastify ×1

nestjs ×1

nestjs-fastify ×1