forked from nestjs/docs.nestjs.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a219cc
commit ae4f109
Showing
7 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/app/homepage/pages/recipes/terminus/terminus.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div class="content"> | ||
<h3>Health Checks (Terminus)</h3> | ||
<p> | ||
Godaddys JavaScript library <a href="https://github.com/godaddy/terminus" target="blank">@godaddy/terminus</a> adds graceful shutdown and Kubernetes readiness / liveness checks for any HTTP applications. | ||
Therefore it is compatible with NestJS using <a href="https://github.com/nestjs/terminus">@nestjs/terminus</a>. Lets get started by installing the required dependencies. | ||
</p> | ||
<pre><code class="language-typescript">{{ dependencies }}</code></pre> | ||
<h4>Health Check</h4> | ||
<p> | ||
The first step we need to do is to setup a service, which will handle the health checks. | ||
</p> | ||
<span class="filename">health.service.ts</span> | ||
<pre><code class="language-typescript">{{ healthService }}</code></pre> | ||
<p> | ||
Once we have set up our <code>HealthService</code>, we can import the <code>TerminusModule</code> into the root <code>ApplicationModule</code>. | ||
The <code>HealthService</code> will all provide the settings, which will be used by the <code>TerminusModule</code> | ||
</p> | ||
<span class="filename">app.module.ts</span> | ||
<pre><code class="language-typescript">{{ appModule }}</code></pre> | ||
<blockquote class="info"> | ||
<strong>Hint</strong> | ||
If done correctly Nest will expose the defined health check(s), which are reachable through a GET request to the defined route. For example <code>curl -X GET 'http://localhost:3000/health'</code> | ||
</blockquote> | ||
<h4>Listen to System Signals (IPC)</h4> | ||
</div> |
49 changes: 49 additions & 0 deletions
49
src/app/homepage/pages/recipes/terminus/terminus.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Component, ChangeDetectionStrategy } from '@angular/core'; | ||
import { BasePageComponent } from '../../page/page.component'; | ||
|
||
@Component({ | ||
selector: 'app-terminus', | ||
templateUrl: './terminus.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class TerminusComponent extends BasePageComponent { | ||
get dependencies() { | ||
return ` | ||
$ npm install --save @nestjs/terminus @godaddy/terminus`; | ||
} | ||
|
||
get healthService() { | ||
return ` | ||
import { Injectable } from '@nestjs/common'; | ||
import { TerminusOptions, TerminusOptionsFactory } from '@nestjs/terminus'; | ||
@Injectable() | ||
export class HealthService implements TerminusOptionsFactory { | ||
async health() { | ||
return true; | ||
} | ||
async createTerminusOptions(): Promise<TerminusOptions> { | ||
return { | ||
healthChecks: { '/health': this.health } | ||
}; | ||
} | ||
}`; | ||
} | ||
|
||
get appModule() { | ||
return ` | ||
import { Module } from '@nestjs/common'; | ||
import { TerminusModule } from '@nestjs/terminus'; | ||
@Module({ | ||
imports: [ | ||
TerminusModule.forRootAsync({ | ||
useClass: TerminusService, | ||
}), | ||
], | ||
}) | ||
export class ApplicationModule {}`; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { TerminusComponent } from './terminus.component'; | ||
|
||
describe('TerminusComponent', () => { | ||
beforeEach(async(() => { | ||
return TestBed.configureTestingModule({ | ||
declarations: [ TerminusComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
let fixture: ComponentFixture<TerminusComponent>; | ||
let component: TerminusComponent; | ||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TerminusComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |