NestJS gRPC 中间件
NestJS gRPC Middlware
NestJS 是否支持带有 gRPC 的中间件?我正在关注示例项目 here and then the middleware for logging the request entrypoint here.
在示例项目中,看起来有一个 Express 服务器和 gRPC 服务器。我只使用 gRPC 服务器。
const app = await NestFactory.createMicroservice<MicroserviceOptions>(...);
await app.listenAsync();
因此将以下内容添加到主应用程序模块中:
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(LoggerMiddleware)
.forRoutes('*');
}
}
但是没有任何日志记录。
中间件专用于 HTTP 处理程序。如果您需要类似中间件的功能,最好使用 Nest 的增强器之一 (guards, interceptors, pipes, or filters)。如果你想做一些日志记录,我建议你使用拦截器,因为你有预控制器和 post- 控制器逻辑。
还有我的日志库 Ogma,它已经有一个 Nest 包和拦截器,可能对查看很有用
NestJS 是否支持带有 gRPC 的中间件?我正在关注示例项目 here and then the middleware for logging the request entrypoint here.
在示例项目中,看起来有一个 Express 服务器和 gRPC 服务器。我只使用 gRPC 服务器。
const app = await NestFactory.createMicroservice<MicroserviceOptions>(...);
await app.listenAsync();
因此将以下内容添加到主应用程序模块中:
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(LoggerMiddleware)
.forRoutes('*');
}
}
但是没有任何日志记录。
中间件专用于 HTTP 处理程序。如果您需要类似中间件的功能,最好使用 Nest 的增强器之一 (guards, interceptors, pipes, or filters)。如果你想做一些日志记录,我建议你使用拦截器,因为你有预控制器和 post- 控制器逻辑。
还有我的日志库 Ogma,它已经有一个 Nest 包和拦截器,可能对查看很有用