@0th/terminus 中文文档教程
一个渐进式 Node.js 框架,用于构建高效且可扩展的服务器端应用程序,深受 角度。
<p align="center">
Description
此模块包含 Nest 的集成健康检查。
Installation
@nestjs/terminus
集成了很多很酷的技术,比如typeorm
、grpc
、mongodb
等等更多的! 如果您错过了依赖项,@nestjs/terminus
将抛出错误并提示您安装所需的依赖项。 所以你只会安装实际需要的东西!
npm install --save @nestjs/terminus
Usage
- Import the Terminus module
- Make sure the additionally needed modules are available to (e.g.
TypeOrmModule
), in case you want to do Database Health Checks.
// app.module.ts
@Module({
controllers: [HealthController],
imports:[
// Make sure TypeOrmModule is available in the module context
TypeOrmModule.forRoot({ ... }),
TerminusModule
],
})
export class HealthModule { }
- Setup your
HealthController
which executes your Health Check.
// health.controller.ts
@Controller('health')
export class HealthController {
constructor(
private health: HealthCheckService,
private db: TypeOrmHealthIndicator,
) {}
@Get()
@HealthCheck()
readiness() {
return this.health.check([
async () => this.db.pingCheck('database', { timeout: 300 }),
]);
}
}
如果一切设置正确,您可以访问 http://localhost:3000/health
上的健康检查。
{
"status": "ok",
"info": {
"database": {
"status": "up"
}
},
"details": {
"database": {
"status": "up"
}
}
}
如需更多信息,请查看文档。 您可以在该存储库的 samples/ 文件夹中找到更多示例。
Support
Nest 是 MIT 许可的开源项目。 由于赞助商和惊人支持者的支持,它可以成长。 如果您想加入他们,请在此处阅读更多信息。
Stay in touch
- Author - Kamil Myśliwiec and Livio Brunner
- Website - https://nestjs.com
- Twitter - @nestframework
License
Nest 已获得 MIT 许可。
A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.
<p align="center">
Description
This module contains integrated healthchecks for Nest.
Installation
@nestjs/terminus
integrates with a lot of cool technologies, such as typeorm
, grpc
, mongodb
, and many more! In case you have missed a dependency, @nestjs/terminus
will throw an error and prompt you to install the required dependency. So you will only install what is actually required!
npm install --save @nestjs/terminus
Usage
- Import the Terminus module
- Make sure the additionally needed modules are available to (e.g.
TypeOrmModule
), in case you want to do Database Health Checks.
// app.module.ts
@Module({
controllers: [HealthController],
imports:[
// Make sure TypeOrmModule is available in the module context
TypeOrmModule.forRoot({ ... }),
TerminusModule
],
})
export class HealthModule { }
- Setup your
HealthController
which executes your Health Check.
// health.controller.ts
@Controller('health')
export class HealthController {
constructor(
private health: HealthCheckService,
private db: TypeOrmHealthIndicator,
) {}
@Get()
@HealthCheck()
readiness() {
return this.health.check([
async () => this.db.pingCheck('database', { timeout: 300 }),
]);
}
}
If everything is set up correctly, you can access the healthcheck on http://localhost:3000/health
.
{
"status": "ok",
"info": {
"database": {
"status": "up"
}
},
"details": {
"database": {
"status": "up"
}
}
}
For more information, see docs. You can find more samples in the samples/ folder of this repository.
Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Stay in touch
- Author - Kamil Myśliwiec and Livio Brunner
- Website - https://nestjs.com
- Twitter - @nestframework
License
Nest is MIT licensed.