1- import { Get , Controller , HttpCode } from '@nestjs/common' ;
1+ import { Get , Controller , HttpCode , Inject } from '@nestjs/common' ;
22import * as fs from 'fs' ;
33import * as path from 'path' ;
44import Handlebars from 'handlebars' ;
5- import { HealtCheckService } from './healt.check.service' ;
5+ import { HealthCheckService } from './health.check.service' ;
6+ import { PATH_METADATA } from '@nestjs/common/constants' ;
7+ import { STATUS_MONITOR_OPTIONS_PROVIDER } from './status.monitor.constants' ;
8+ import { StatusMonitorConfiguration } from './config/status.monitor.configuration' ;
69
7- const controllerPath = 'monitor' ;
8-
9- @Controller ( controllerPath )
10+ @Controller ( )
1011export class StatusMonitorController {
1112 data ;
1213 render ;
1314
14- constructor ( private readonly healtCheckService : HealtCheckService ) {
15+ constructor (
16+ private readonly healtCheckService : HealthCheckService ,
17+ @Inject ( STATUS_MONITOR_OPTIONS_PROVIDER )
18+ private readonly config : StatusMonitorConfiguration ,
19+ ) {
20+ const bodyClasses = Object . keys ( config . chartVisibility )
21+ . reduce ( ( accumulator , key ) => {
22+ if ( config . chartVisibility [ key ] === false ) {
23+ accumulator . push ( `hide-${ key } ` ) ;
24+ }
25+ return accumulator ;
26+ } , [ ] )
27+ . join ( ' ' ) ;
28+
1529 this . data = {
16- title : 'Nest.js Status' ,
17- port : 3001 ,
18- bodyClasses : '' ,
30+ title : config . pageTitle ,
31+ port : config . port ,
32+ bodyClasses : bodyClasses ,
1933 script : fs . readFileSync (
2034 path . join ( __dirname , '../src/public/javascripts/app.js' ) ,
2135 ) ,
@@ -31,6 +45,11 @@ export class StatusMonitorController {
3145 this . render = Handlebars . compile ( htmlTmpl , { strict : true } ) ;
3246 }
3347
48+ public static forRoot ( rootPath : string = 'monitor' ) {
49+ Reflect . defineMetadata ( PATH_METADATA , rootPath , StatusMonitorController ) ;
50+ return StatusMonitorController ;
51+ }
52+
3453 @Get ( )
3554 @HttpCode ( 200 )
3655 async root ( ) {
0 commit comments