mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-24 02:22:08 +02:00
api/core: return 429 http status for rate-limit (#1066)
Co-authored-by: jj <log@riseup.net>
This commit is contained in:
parent
ad23b70e9d
commit
fa267ae54b
@ -61,13 +61,13 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleRateExceeded = (_, res) => {
|
const handleRateExceeded = (_, res) => {
|
||||||
const { status, body } = createResponse("error", {
|
const { body } = createResponse("error", {
|
||||||
code: "error.api.rate_exceeded",
|
code: "error.api.rate_exceeded",
|
||||||
context: {
|
context: {
|
||||||
limit: env.rateLimitWindow
|
limit: env.rateLimitWindow
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res.status(status).json(body);
|
return res.status(429).json(body);
|
||||||
};
|
};
|
||||||
|
|
||||||
const keyGenerator = (req) => hashHmac(getIP(req), 'rate').toString('base64url');
|
const keyGenerator = (req) => hashHmac(getIP(req), 'rate').toString('base64url');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user