Skip to content

Commit

Permalink
fix(terminus): Change AppRefHost to HttpAdapterHost
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunnerLivio committed Mar 17, 2019
1 parent f7b114b commit 52e212b
Show file tree
Hide file tree
Showing 6 changed files with 807 additions and 1,512 deletions.
6 changes: 4 additions & 2 deletions e2e/helper/bootstrap-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { DynamicModule, INestApplication } from '@nestjs/common';
import { FastifyAdapter, NestFactory } from '@nestjs/core';
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter } from '@nestjs/platform-fastify';
import { ExpressAdapter } from '@nestjs/platform-express';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MongooseModule } from '@nestjs/mongoose';
import * as portfinder from 'portfinder';
Expand Down Expand Up @@ -64,7 +66,7 @@ export async function bootstrapModule(
): Promise<[INestApplication, number]> {
const app = await NestFactory.create(
ApplicationModule.forRoot(options, useDb, useMongoose),
useFastify ? new FastifyAdapter() : null,
useFastify ? new FastifyAdapter() : new ExpressAdapter(),
);

if (tcpPort) {
Expand Down
7 changes: 4 additions & 3 deletions e2e/terminus.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { INestApplication, DynamicModule } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { TerminusModule } from '../lib/terminus.module';
import { TerminusLibProvider } from '../lib/terminus-lib.provider';
import { ApplicationReferenceHost } from '@nestjs/core';
import { HttpAdapterHost } from '@nestjs/core';
import {
TerminusOptionsFactory,
TerminusModuleOptions,
Expand Down Expand Up @@ -40,8 +40,9 @@ describe('Terminus', () => {
.compile();

app = module.createNestApplication();
httpServer = app.get<ApplicationReferenceHost>(ApplicationReferenceHost)
.applicationRef.httpServer;
httpServer = app
.get<HttpAdapterHost>(HttpAdapterHost)
.httpAdapter.getHttpServer();
await app.init();
return app;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/terminus-bootstrap.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TerminusBootstrapService } from './terminus-bootstrap.service';
import { ApplicationReferenceHost } from '@nestjs/core';
import { HttpAdapterHost } from '@nestjs/core';
import { TerminusEndpoint, TerminusModuleOptions } from './interfaces';
import { HealthCheckError } from '@godaddy/terminus';

const httpServer = jest.fn();

const refhostMock = {
applicationRef: {
httpAdapter: {
getHttpServer: jest.fn().mockImplementation(() => httpServer),
},
};
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('TerminusBootstrapService', () => {
const bootstrapService = new TerminusBootstrapService(
options,
terminus,
refhostMock as ApplicationReferenceHost,
refhostMock as HttpAdapterHost<any>,
);

expect(terminus).not.toHaveBeenCalled();
Expand All @@ -61,7 +61,7 @@ describe('TerminusBootstrapService', () => {
const bootstrapService = new TerminusBootstrapService(
{ ...options, logger },
terminus,
refhostMock as ApplicationReferenceHost,
refhostMock as HttpAdapterHost<any>,
);

bootstrapService.onApplicationBootstrap();
Expand All @@ -79,7 +79,7 @@ describe('TerminusBootstrapService', () => {
bootstrapService = new TerminusBootstrapService(
options,
terminus,
refhostMock as ApplicationReferenceHost,
refhostMock as HttpAdapterHost<any>,
);
});

Expand Down
9 changes: 5 additions & 4 deletions lib/terminus-bootstrap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
HealthIndicatorFunction,
TerminusEndpoint,
} from './interfaces';
import { ApplicationReferenceHost } from '@nestjs/core';
import { HttpAdapterHost } from '@nestjs/core';
import { Server } from 'http';
import { HealthCheckError, Terminus, HealthCheckMap } from '@godaddy/terminus';

Expand Down Expand Up @@ -38,8 +38,9 @@ export class TerminusBootstrapService implements OnApplicationBootstrap {
constructor(
@Inject(TERMINUS_MODULE_OPTIONS)
private readonly options: TerminusModuleOptions,
@Inject(TERMINUS_LIB) private readonly terminus: Terminus,
private readonly refHost: ApplicationReferenceHost,
@Inject(TERMINUS_LIB)
private readonly terminus: Terminus,
private readonly refHost: HttpAdapterHost<any>,
) {}

/**
Expand Down Expand Up @@ -157,7 +158,7 @@ export class TerminusBootstrapService implements OnApplicationBootstrap {
*/
public onApplicationBootstrap() {
// httpServer for express, instance.server for fastify
this.httpServer = this.refHost.applicationRef.getHttpServer();
this.httpServer = this.refHost.httpAdapter.getHttpServer();
this.bootstrapTerminus();
}
}
Loading

0 comments on commit 52e212b

Please sign in to comment.