fastify-txstate 3.1.7 → 3.1.9

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.
package/lib/index.js CHANGED
@@ -126,13 +126,13 @@ class Server {
126
126
  }
127
127
  this.app.addHook('onSend', this.https && process.env.NODE_ENV !== 'development'
128
128
  ? async (_, resp) => {
129
- resp.removeHeader('X-Powered-By');
129
+ void resp.removeHeader('X-Powered-By');
130
130
  void resp.header('Strict-Transport-Security', 'max-age=31536000');
131
131
  if (resp.getHeader('content-type') === 'text/html')
132
132
  void resp.type('text/html; charset=utf-8');
133
133
  }
134
134
  : async (_, resp) => {
135
- resp.removeHeader('X-Powered-By');
135
+ void resp.removeHeader('X-Powered-By');
136
136
  if (resp.getHeader('content-type') === 'text/html')
137
137
  void resp.type('text/html; charset=utf-8');
138
138
  });
@@ -162,7 +162,7 @@ class Server {
162
162
  if (this.shuttingDown) {
163
163
  res.log.info('Returning 503 on /health because we are shutting down/restarting.');
164
164
  void res.status(503);
165
- return 'Service is shutting down/restarting.';
165
+ return 'MAINTENANCE';
166
166
  }
167
167
  else if (this.healthMessage) {
168
168
  res.log.info(this.healthMessage);
@@ -170,11 +170,12 @@ class Server {
170
170
  return this.healthMessage;
171
171
  }
172
172
  else if (this.healthCallback) {
173
- const msg = await this.healthCallback();
174
- if (msg) {
175
- res.log.info(msg);
176
- void res.status(500);
177
- return msg;
173
+ const resp = await this.healthCallback();
174
+ const [status, msg] = typeof resp === 'string' ? [500, resp] : [resp === null || resp === void 0 ? void 0 : resp.status, resp === null || resp === void 0 ? void 0 : resp.message];
175
+ if (!!msg || !!status) {
176
+ res.log.info(resp, 'Health check callback failed.');
177
+ void res.status(status !== null && status !== void 0 ? status : 500);
178
+ return msg !== null && msg !== void 0 ? msg : 'FAIL';
178
179
  }
179
180
  }
180
181
  return 'OK';
@@ -16,7 +16,10 @@ export interface FastifyTxStateOptions extends Partial<FastifyServerOptions> {
16
16
  *
17
17
  * Setting a health message with setUnhealthy will override this and prevent it from being executed.
18
18
  */
19
- checkHealth?: () => Promise<string | undefined>;
19
+ checkHealth?: () => Promise<string | {
20
+ status?: number;
21
+ message?: string;
22
+ } | undefined>;
20
23
  }
21
24
  declare module 'fastify' {
22
25
  interface FastifyReply {
@@ -54,7 +57,10 @@ export default class Server {
54
57
  protected https: boolean;
55
58
  protected errorHandlers: ErrorHandler[];
56
59
  protected healthMessage?: string;
57
- protected healthCallback?: () => Promise<string | undefined>;
60
+ protected healthCallback?: () => Promise<string | {
61
+ status?: number;
62
+ message?: string;
63
+ } | undefined>;
58
64
  protected shuttingDown: boolean;
59
65
  protected sigHandler: (signal: any) => void;
60
66
  protected validOrigins: Record<string, boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-txstate",
3
- "version": "3.1.7",
3
+ "version": "3.1.9",
4
4
  "description": "A small wrapper for fastify providing a set of common conventions & utility functions we use.",
5
5
  "exports": {
6
6
  "types": "./lib-esm/index.d.ts",