Skip to content

Commit

Permalink
Add nest/terminus documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunnerLivio committed Sep 12, 2018
1 parent 5a219cc commit ae4f109
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 8 deletions.
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { PassportComponent } from './homepage/pages/recipes/passport/passport.co
import { SqlSequelizeComponent } from './homepage/pages/recipes/sql-sequelize/sql-sequelize.component';
import { SqlTypeormComponent } from './homepage/pages/recipes/sql-typeorm/sql-typeorm.component';
import { SwaggerComponent } from './homepage/pages/recipes/swagger/swagger.component';
import { TerminusComponent } from './homepage/pages/recipes/terminus/terminus.component';
import { SupportComponent } from './homepage/pages/support/support.component';
import { AuthenticationComponent } from './homepage/pages/techniques/authentication/authentication.component';
import { CachingComponent } from './homepage/pages/techniques/caching/caching.component';
Expand Down Expand Up @@ -320,6 +321,11 @@ const routes: Routes = [
component: MongodbComponent,
data: { title: 'MongoDB (Mongoose)' },
},
{
path: 'recipes/terminus',
component: TerminusComponent,
data: { title: 'Terminus' },
},
/*{
path: 'recipes/mockgoose',
component: MockgooseComponent,
Expand Down Expand Up @@ -489,4 +495,4 @@ const routes: Routes = [
],
exports: [RouterModule],
})
export class AppRoutingModule {}
export class AppRoutingModule { }
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import { CompressionComponent } from './homepage/pages/techniques/compression/co
import { ValidationComponent } from './homepage/pages/techniques/validation/validation.component';
import { CachingComponent } from './homepage/pages/techniques/caching/caching.component';
import { SerializationComponent } from './homepage/pages/techniques/serialization/serialization.component';
import { TerminusComponent } from './homepage/pages/recipes/terminus/terminus.component';

const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
suppressScrollX: true,
Expand Down Expand Up @@ -149,6 +150,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
MockgooseComponent,
PassportComponent,
SwaggerComponent,
TerminusComponent,
CqrsComponent,
TabsComponent,
ExtensionPipe,
Expand Down
1 change: 1 addition & 0 deletions src/app/homepage/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class MenuComponent implements OnInit {
// { title: 'Authentication (Passport)', path: '/recipes/passport' },
{ title: 'CQRS', path: '/recipes/cqrs' },
{ title: 'OpenAPI (Swagger)', path: '/recipes/swagger' },
{ title: 'Health Checks (Terminus)', path: '/recipes/terminus'}
],
},
{
Expand Down
25 changes: 25 additions & 0 deletions src/app/homepage/pages/recipes/terminus/terminus.component.html
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 src/app/homepage/pages/recipes/terminus/terminus.component.ts
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 {}`;
}

}
24 changes: 24 additions & 0 deletions src/app/homepage/pages/recipes/terminus/terminus.spec.ts
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();
});
});

0 comments on commit ae4f109

Please sign in to comment.