Skip to content

Commit

Permalink
fix: remove mandatory @godaddy/terminus imports
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunnerLivio committed Apr 5, 2020
1 parent 56da0bc commit dceb5db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
14 changes: 5 additions & 9 deletions lib/terminus-bootstrap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ import {
import { TERMINUS_MODULE_OPTIONS, TERMINUS_LIB } from './terminus.constants';
import { HttpAdapterHost, ApplicationConfig } from '@nestjs/core';
import { Server } from 'http';
import type {
HealthCheckError,
Terminus,
HealthCheckMap,
} from '@godaddy/terminus';
import { validatePath } from '@nestjs/common/utils/shared.utils';
import { HealthCheckExecutor } from './health-check/health-check-executor.service';
import {
TerminusModuleOptions,
TerminusEndpoint,
} from './terminus-module-options.interface';
import { HealthCheckError } from './health-check';

export const SIG_NOT_EXIST = 'SIG_NOT_EXIST';

Expand All @@ -40,7 +36,7 @@ export class TerminusBootstrapService implements OnApplicationBootstrap {
@Inject(TERMINUS_MODULE_OPTIONS)
private readonly options: TerminusModuleOptions,
@Inject(TERMINUS_LIB)
private readonly terminus: Terminus,
private readonly terminus: any,
private readonly healthCheckExecutor: HealthCheckExecutor,
private readonly refHost: HttpAdapterHost<any>,
private readonly applicationConfig: ApplicationConfig,
Expand All @@ -63,7 +59,7 @@ export class TerminusBootstrapService implements OnApplicationBootstrap {
* Logs the health check registration to the logger
* @param healthChecks The health check map to log
*/
private logHealthCheckRegister(healthChecks: HealthCheckMap) {
private logHealthCheckRegister(healthChecks: any) {
Object.keys(healthChecks).forEach((endpoint) =>
this.logger.log(
`Mapped {${endpoint}, GET} healthcheck route`,
Expand Down Expand Up @@ -95,13 +91,13 @@ export class TerminusBootstrapService implements OnApplicationBootstrap {
* Returns the health check map using the configured health
* indicators
*/
public getHealthChecksMap(): HealthCheckMap {
public getHealthChecksMap(): any {
return this.options.endpoints.reduce((healthChecks, endpoint) => {
const url = this.validateEndpointUrl(endpoint);
healthChecks[url] = async () =>
this.healthCheckExecutor.executeDeprecated(endpoint.healthIndicators);
return healthChecks;
}, {} as HealthCheckMap);
}, {} as any);
}

/**
Expand Down
16 changes: 13 additions & 3 deletions lib/terminus-lib.provider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { TERMINUS_LIB } from './terminus.constants';
import { createTerminus } from '@godaddy/terminus';
import { Provider } from '@nestjs/common';
import { checkPackages } from './utils';

/**
* Create a wrapper so it is injectable & easier to test
*
* @internal
*/
export const TerminusLibProvider = {
export const TerminusLibProvider: Provider = {
provide: TERMINUS_LIB,
useValue: createTerminus,
useFactory: () => {
const [terminus] = checkPackages(
['@godaddy/terminus'],
'the legacy Terminus API',
);
if (!terminus) {
process.exit(1);
}
return terminus.createTerminus;
},
};
2 changes: 1 addition & 1 deletion package-lock.json

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

0 comments on commit dceb5db

Please sign in to comment.