-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Do not cache health checks per default (#2335)
When using the `@HealthCheck` decorator it will now per default set the following header: `Cache-Control: no-cache, no-store, must-revalidate` To disable this behavior set `@HealthCheck({ noCache: false })` resolves #2328
- Loading branch information
1 parent
781c00e
commit 262c808
Showing
3 changed files
with
104 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as request from 'supertest'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import { DynamicHealthEndpointFn, bootstrapTestingModule } from '../helper'; | ||
import { HealthIndicatorResult } from '../../lib'; | ||
|
||
describe.only('HealthCheck', () => { | ||
let app: INestApplication; | ||
let setHealthEndpoint: DynamicHealthEndpointFn; | ||
|
||
const healthyCheck = () => | ||
Promise.resolve<HealthIndicatorResult>({ status: 'up' } as any); | ||
|
||
beforeEach( | ||
() => (setHealthEndpoint = bootstrapTestingModule().setHealthEndpoint), | ||
); | ||
|
||
it('should set the Cache-Control header to no-cache, no-store, must-revalidate', async () => { | ||
app = await setHealthEndpoint(({ healthCheck }) => | ||
healthCheck.check([healthyCheck]), | ||
).start(); | ||
|
||
return request(app.getHttpServer()) | ||
.get('/health') | ||
.expect('Cache-Control', 'no-cache, no-store, must-revalidate'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters