feat: rate limit error chaching

Rate limit error caching to alleviate PATs.
This commit is contained in:
Rick Staa
2023-01-21 18:50:37 +01:00
committed by rickstaa
parent 60fae292a3
commit aa2e8ff3c5
8 changed files with 48 additions and 17 deletions
+7 -2
View File
@@ -171,13 +171,18 @@ describe("Test /api/", () => {
]);
});
it("should not store cache when error", async () => {
it("should set shorter cache when error", async () => {
const { req, res } = faker({}, error);
await api(req, res);
expect(res.setHeader.mock.calls).toEqual([
["Content-Type", "image/svg+xml"],
["Cache-Control", `no-cache, no-store, must-revalidate`],
[
"Cache-Control",
`max-age=${CONSTANTS.ERROR_CACHE_SECONDS / 2}, s-maxage=${
CONSTANTS.ERROR_CACHE_SECONDS
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
],
]);
});