Skip to content

Commit b721be4

Browse files
committed
feat(config): add server.skipHealthz option for health check bypass
1 parent 07f8b1b commit b721be4

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ export let config = {
7676
* Default TTL (time to live) for cache entries in seconds
7777
*/
7878
defaultTtl: Env.getNumber('CACHE_DEFAULT_TTL_SECONDS', 3600) * 1000
79+
},
80+
81+
server: {
82+
/**
83+
* Skip healthz endpoint even if health checks are configured
84+
* Default: false
85+
* Set to true to return 200 OK for /healthz without checks
86+
* Useful in environments where a simple liveness probe is needed
87+
* without performing actual health checks
88+
* Example: Kubernetes liveness probe
89+
* Note: This does not disable the health check functionality itself
90+
* Health checks can still be performed programmatically
91+
* or via other endpoints if needed
92+
*/
93+
skipHealthz: Env.getBoolean('SERVER_SKIP_HEALTHZ', false)
7994
}
8095
};
8196

src/servers/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { getLogger } from '../utils/logger.utils';
3333
import { InternalServerErrorException, ServiceUnavailableException } from '../utils/exception.utils';
3434
import { NotFoundException } from '../utils/exception.utils';
3535
import fs from 'fs';
36-
import { defaultServerConfig } from '../config';
36+
import { config, defaultServerConfig } from '../config';
3737
import { deepObjMerge } from '../utils/obj.utils';
3838
import { fileExists } from '../utils/fs.utils';
3939
import { Socket } from 'net';
@@ -575,7 +575,7 @@ export class ExpressServer {
575575

576576
this.app.get(healthCheckPath, async (_req: Request, res: Response) => {
577577
try {
578-
if (!this.healthChecks.length) {
578+
if (!this.healthChecks.length || config.server.skipHealthz) {
579579
return res.status(HttpStatusCodes.OK).json(new SuccessResponse('OK'));
580580
}
581581

tests/config.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ describe('config', () => {
105105
},
106106
cache: {
107107
defaultTtl: 3600000
108+
},
109+
server: {
110+
skipHealthz: false
108111
}
109112
});
110113
});

0 commit comments

Comments
 (0)