@seas-computing/nestjs-healthcheck 0.0.5-14 → 0.0.5-15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +98 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -13,9 +13,14 @@ npm install @seas-computing/nestjs-healthcheck
13
13
 
14
14
  ## Usage
15
15
 
16
- Add the `HealthCheckController` to the consuming application's `AppModule` (or other root module), along with providers for the `CONFIG_SERVICE`, `TypeOrmHealthIndicator`, `HttpHealthIndicator`, and `RedisHealthService`.
16
+ To add the nestjs healthcheck system, you should make the following changes in the consuming application's `AppModule` (or other root module):
17
+ - import and register the `HealthcheckModule` using `registerAsync`
18
+ - be sure that the `ConfigModule` is at the top of the imports list
19
+ - import `TypeOrmHealthIndicator`, `HttpHealthIndicator`, and `RedisHealthService`
17
20
 
18
- Example from makerspace:
21
+ In the `ConfigService`, configuration values (i.e. `HealthcheckModuleOptions`) should be made available and passed as options to the `HealthcheckModule`.
22
+
23
+ Example `app.module` from [makerspace](https://github.huit.harvard.edu/SEAS/makerspace/blob/feature/add-healthcheck-module/src/server/app.module.ts):
19
24
  ```ts
20
25
  @Module({
21
26
  imports: [
@@ -80,7 +85,27 @@ Example from makerspace:
80
85
  AttendanceModule,
81
86
  UserModule,
82
87
  KioskModule,
83
- HealthCheckModule, // Add HealthCheckModule
88
+ HealthcheckModule.registerAsync({ // Add HealthCheckModule
89
+ imports: [ConfigModule],
90
+ inject: [ConfigService],
91
+ useFactory: (configService: ConfigService): HealthcheckModuleOptions => {
92
+ const casHealthcheckUrl = configService.casCheckURL;
93
+ if (!casHealthcheckUrl) throw new Error('casCheckURL is not defined or is invalid in configuration.');
94
+ try {
95
+ new URL(casHealthcheckUrl);
96
+ } catch (error) {
97
+ if (error instanceof Error) {
98
+ throw new Error(`casCheckURL is not a valid URL. ${error}`);
99
+ } else {
100
+ throw error;
101
+ }
102
+ }
103
+ return {
104
+ ...configService.healthcheckConfig,
105
+ casCheckURL: casHealthcheckUrl,
106
+ };
107
+ },
108
+ }),
84
109
  ],
85
110
  controllers: [],
86
111
  providers: [],
@@ -100,4 +125,74 @@ class AppModule implements NestModule {
100
125
 
101
126
  export { AppModule };
102
127
 
128
+ ```
129
+
130
+ Examples of additions to `config.service.ts` from [makerspace](https://github.huit.harvard.edu/SEAS/makerspace/blob/feature/add-healthcheck-module/src/server/config/config.service.ts):
131
+
132
+ ```ts
133
+ /**
134
+ * Returns the full healthcheck endpoint for HarvardKey CAS, which will be sent to
135
+ * the Healthcheck Module. It strips out any auth credentials, query strings, and
136
+ * hashes, normalizes the path to ensure there is only one `/cas` segment, and
137
+ * appends `/logout` to the end.
138
+ */
139
+ public get casCheckURL(): string {
140
+ const {
141
+ origin,
142
+ pathname,
143
+ } = this.casURL;
144
+ let cleanPath = pathname.replace(/\/$/, '');
145
+ cleanPath = cleanPath.replace(/\/(login|logout)$/, '');
146
+ if (!cleanPath.endsWith('/cas')) {
147
+ cleanPath += '/cas';
148
+ }
149
+ return `${origin}${cleanPath}/logout`;
150
+ }
151
+
152
+ public get healthcheckConfig(): HealthcheckModuleOptions {
153
+ return {
154
+ casCheckURL: this.casCheckURL,
155
+ dbOptions: this.dbOptions,
156
+ redisUrl: this.redisURL,
157
+ version: this.buildVersion,
158
+ strategy: this.isProduction
159
+ ? HEALTH_STRATEGY_NAME.HEALTHCHECK
160
+ : HEALTH_STRATEGY_NAME.DEV,
161
+ };
162
+ }
163
+ ```
164
+
165
+ ## Sample Response
166
+
167
+ You should receive a response that looks like this:
168
+
169
+ ```json
170
+ {
171
+ "status": "ok",
172
+ "info": {
173
+ "database": {
174
+ "status": "up"
175
+ },
176
+ "harvard-key": {
177
+ "status": "up"
178
+ },
179
+ "redis": {
180
+ "status": "up",
181
+ "result": "PONG"
182
+ }
183
+ },
184
+ "error": {},
185
+ "details": {
186
+ "database": {
187
+ "status": "up"
188
+ },
189
+ "harvard-key": {
190
+ "status": "up"
191
+ },
192
+ "redis": {
193
+ "status": "up",
194
+ "result": "PONG"
195
+ }
196
+ }
197
+ }
103
198
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seas-computing/nestjs-healthcheck",
3
- "version": "0.0.5-14",
3
+ "version": "0.0.5-15",
4
4
  "description": "A standalone healthcheck module for NestJS apps",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",