fix: cache negative custom domain CORS lookups
Use a shorter TTL for rejected origins so unknown domains do not hit the database on every cross-origin request.
This commit is contained in:
1 parent
ef049b6521
commit
517139cbf4
2 files changed
+28
-5
No files matched your search
@@ -56,5 +56,19 @@ describe("createStatusPageCorsOrigin", () => {
|
||||
const originFn = createStatusPageCorsOrigin("https://checkmate.example.com", repo as IStatusPagesRepository);
|
||||
|
||||
await expect(invokeOrigin(originFn, "https://status.example.com")).resolves.toBe(false);
|
||||
await expect(invokeOrigin(originFn, "https://status.example.com")).resolves.toBe(false);
|
||||
|
||||
expect(repo.findByCustomDomain).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("caches unknown custom domain lookups", async () => {
|
||||
repo.findByCustomDomain.mockRejectedValue(new Error("Status page not found"));
|
||||
const originFn = createStatusPageCorsOrigin("https://checkmate.example.com", repo as IStatusPagesRepository);
|
||||
|
||||
await expect(invokeOrigin(originFn, "https://unknown.example.com")).resolves.toBe(false);
|
||||
await expect(invokeOrigin(originFn, "https://unknown.example.com")).resolves.toBe(false);
|
||||
|
||||
expect(repo.findByCustomDomain).toHaveBeenCalledTimes(1);
|
||||
expect(repo.findByCustomDomain).toHaveBeenCalledWith("unknown.example.com");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user