Skip to content

Commit 46d9308

Browse files
committed
Added healthcheck
Update the dependencies for security reason (PR) Change the redirection to the api document
1 parent c8b406a commit 46d9308

File tree

11 files changed

+116
-73
lines changed

11 files changed

+116
-73
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.3.1] - 2020-08-07
8+
### Fixed
9+
- Updated the dependencies (PR1)
10+
11+
### Added
12+
- Healthcheck (/health)
13+
14+
### Changed
15+
- Removed the old simple healthcheck.
16+
717
## [0.3.0] - 2020-08-05
818
### Changed
919
- Instead of reading the filesystem the checks will run against a sqlite database

package-lock.json

Lines changed: 41 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
"test:e2e": "jest --config ./test/jest-e2e.json"
2323
},
2424
"dependencies": {
25-
"@nestjs/common": "^7.4.1",
25+
"@nestjs/common": "^7.4.2",
2626
"@nestjs/config": "^0.5.0",
27-
"@nestjs/core": "^7.4.1",
28-
"@nestjs/platform-express": "^7.4.1",
27+
"@nestjs/core": "^7.4.2",
28+
"@nestjs/platform-express": "^7.4.2",
2929
"@nestjs/swagger": "^4.5.12",
30+
"@nestjs/terminus": "^7.0.1",
3031
"@nestjs/typeorm": "^7.1.0",
3132
"axios": "^0.19.2",
32-
"class-transformer": "^0.2.3",
33+
"class-transformer": "0.3.1",
3334
"class-validator": "^0.12.2",
3435
"form-data": "^3.0.0",
3536
"jest-junit": "^10.0.0",
@@ -39,7 +40,7 @@
3940
"puppeteer": "^3.3.0",
4041
"reflect-metadata": "^0.1.13",
4142
"rimraf": "^3.0.2",
42-
"rxjs": "^6.6.0",
43+
"rxjs": "^6.6.2",
4344
"signed": "^1.0.3",
4445
"sqlite3": "^5.0.0",
4546
"swagger-ui-express": "^4.1.4",
@@ -49,7 +50,7 @@
4950
"devDependencies": {
5051
"@nestjs/cli": "^7.4.1",
5152
"@nestjs/schematics": "^7.0.0",
52-
"@nestjs/testing": "^7.4.1",
53+
"@nestjs/testing": "^7.4.2",
5354
"@types/express": "^4.17.7",
5455
"@types/jest": "25.2.3",
5556
"@types/node": "^13.13.15",

src/app.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export class AppController {
99
constructor(private readonly appService: AppService) {}
1010

1111
@Get('/')
12-
@ApiResponse({ status: 303, description: 'Will redirect to the healthcheck (/api/status).' })
12+
@ApiResponse({ status: 303, description: 'Will redirect to documentation.' })
1313
@ApiTags("System")
1414
postAuthRequest(@Res() response: express.Response) {
15-
return response.redirect(303, `/api/status`);
15+
return response.redirect(303, `/api`);
1616
}
1717
}

src/app.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Module, MiddlewareConsumer, RequestMethod } from '@nestjs/common';
22
import { AppController } from './app.controller';
33
import { AppService } from './app.service';
4-
import { SystemModule } from './system/system.module';
54
import { BrowserModule } from './browser/browser.module';
65

76
import { TypeOrmModule } from '@nestjs/typeorm';
@@ -10,19 +9,21 @@ import configuration from './configuration/configuration';
109

1110
import { ConfigModule } from '@nestjs/config';
1211
import { ConfigurationModule } from './configuration/configuration.module';
12+
import { TerminusModule } from '@nestjs/terminus';
13+
import { HealthController } from './health/health.controller';
1314

1415
@Module({
1516
imports: [ConfigModule.forRoot({
1617
isGlobal: true,
1718
load: [configuration],
1819
envFilePath: ['.env']
19-
}), SystemModule, BrowserModule, ConfigurationModule, TypeOrmModule.forRoot({
20+
}), BrowserModule, ConfigurationModule,TerminusModule, TypeOrmModule.forRoot({
2021
type: 'sqlite',
2122
database: __dirname + '/../database/database.sqlite',
2223
entities: [__dirname + '/**/*.entity{.ts,.js}'],
2324
synchronize: true,
2425
})],
25-
controllers: [AppController],
26+
controllers: [AppController, HealthController],
2627
providers: [AppService],
2728
})
2829
export class AppModule {

src/configuration/configuration.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ export default () => ({
1616
browseDestroy: process.env.PERMISSION_BROWSE_DELETE || 'browse-delete',
1717
browseRead: process.env.PERMISSION_BROWSE_READ || 'browse-read'
1818
},
19-
browser: process.env.BROWSER_PATH || null
19+
browser: process.env.BROWSER_PATH || null,
20+
healthcheck: {
21+
dnsUrl: process.env.HEALTHCHECK_DNS_CHECK_URL || 'https://google.com',
22+
}
2023
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { HealthController } from './health.controller';
3+
4+
describe('Health Controller', () => {
5+
let controller: HealthController;
6+
7+
beforeEach(async () => {
8+
const module: TestingModule = await Test.createTestingModule({
9+
controllers: [HealthController],
10+
}).compile();
11+
12+
controller = module.get<HealthController>(HealthController);
13+
});
14+
15+
it('should be defined', () => {
16+
expect(controller).toBeDefined();
17+
});
18+
});

src/health/health.controller.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Controller, Get } from '@nestjs/common';
2+
import { HealthCheckService, DNSHealthIndicator, HealthCheck, TypeOrmHealthIndicator } from '@nestjs/terminus';
3+
import { ConfigService } from '@nestjs/config';
4+
import { ApiOperation, ApiTags } from '@nestjs/swagger';
5+
6+
@Controller('health')
7+
export class HealthController {
8+
9+
constructor(
10+
private health: HealthCheckService,
11+
private dns: DNSHealthIndicator,
12+
private db: TypeOrmHealthIndicator,
13+
private configService: ConfigService
14+
) {}
15+
16+
@Get()
17+
@HealthCheck()
18+
@ApiOperation({description: 'Check the health of the service'})
19+
@ApiTags('Healthcheck')
20+
check() {
21+
22+
let dnsCheckUrl = this.configService.get<string>('healthcheck.dnsUrl')
23+
24+
return this.health.check([
25+
async () => this.dns.pingCheck('dnscheck', dnsCheckUrl),
26+
async () => this.db.pingCheck('database', { timeout: 300 }),
27+
]);
28+
}
29+
30+
}

src/system/system.controller.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/system/system.module.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)