-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FN-3611): updated and renamed cache middlewear and added test
- Loading branch information
Zain Kassam
committed
Jan 27, 2025
1 parent
bbb1a5c
commit 752ae10
Showing
5 changed files
with
40 additions
and
18 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './feature-flags'; | ||
export * from './create-validation-middleware-for-schema'; | ||
export * from './set-no-store-cache-control'; | ||
export * from './set-cache-control'; |
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,21 @@ | ||
import request from 'supertest'; | ||
import express from 'express'; | ||
import { HttpStatusCode } from 'axios'; | ||
import { setCacheControl } from './set-cache-control'; | ||
|
||
const app = express(); | ||
app.use(setCacheControl); | ||
app.get('/', (_req, res) => res.send()); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('set-no-store-cache-control', () => { | ||
it('should set Cache-Control headers correctly', async () => { | ||
const response = await request(app).get('/'); | ||
|
||
expect(response.headers['cache-control']).toBe('no-cache, no-store, must-revalidate, max-age=0'); | ||
expect(response.status).toBe(HttpStatusCode.Ok); | ||
}); | ||
}); |
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,15 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
|
||
/** | ||
* middleware to set Cache-Control to no-store, no-cache, must-revalidate and max-age=0 | ||
* stops cached version of a page being rendered when going back to a page (using the browser back button) | ||
* ensures the get controller for the page is called | ||
* @param _req | ||
* @param res | ||
* @param next | ||
*/ | ||
export const setCacheControl = (_req: Request, res: Response, next: NextFunction) => { | ||
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate, max-age=0'); | ||
|
||
next(); | ||
}; |
This file was deleted.
Oops, something went wrong.
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