Give the menu reserve route its own request limit

Every page reads the reserve for the Sokko TCG menu count, and those reads
shared the game API limit of 60 requests per minute and per address. Browser
tests reloading many pages from one address got 429 responses. The route now
has its own limit, like the public configuration, and focus or tab returns
read it at most once every 15 seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-08 00:01:21 +01:00
parent 0723d97788
commit 4db6489760
3 changed files with 26 additions and 9 deletions

View file

@ -376,3 +376,12 @@ test("the reserve route answers visitors without an account and returns the play
assert.equal(reserve.json.recharge.openingsBalance, state.json.recharge.openingsBalance);
assert.equal(reserve.json.recharge.nextOpeningAt, state.json.recharge.nextOpeningAt);
});
test("menu reserve reads do not use up the game's request limit", async (t) => {
const handler = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, apiRateLimit: 2 });
t.after(() => handler.close());
const reserveStatuses = [];
for (let index = 0; index < 5; index += 1) reserveStatuses.push((await call(handler, { path: "/api/cards/reserve" })).status);
assert.deepEqual(reserveStatuses, [200, 200, 200, 200, 429]);
assert.equal((await call(handler, { path: "/api/cards/session" })).status, 200);
});