mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Force no-store header on server error and rate limit responses
This commit is contained in:
parent
afa0a337d3
commit
3fdd6e2213
2 changed files with 6 additions and 0 deletions
|
|
@ -2,6 +2,8 @@ import { ErrorHandler } from '@hono/hono';
|
||||||
import { HTTPException } from '@hono/hono/http-exception';
|
import { HTTPException } from '@hono/hono/http-exception';
|
||||||
|
|
||||||
export const errorHandler: ErrorHandler = (err, c) => {
|
export const errorHandler: ErrorHandler = (err, c) => {
|
||||||
|
c.header('Cache-Control', 'no-store');
|
||||||
|
|
||||||
if (err instanceof HTTPException) {
|
if (err instanceof HTTPException) {
|
||||||
if (err.res) {
|
if (err.res) {
|
||||||
return err.res;
|
return err.res;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ export function rateLimitMiddleware(limit: number, windowMs: number): Middleware
|
||||||
return rateLimiter({
|
return rateLimiter({
|
||||||
limit,
|
limit,
|
||||||
windowMs,
|
windowMs,
|
||||||
|
handler: (c) => {
|
||||||
|
c.header('Cache-Control', 'no-store');
|
||||||
|
return c.text('Too many requests, please try again later.', 429);
|
||||||
|
},
|
||||||
skip: (c) => !c.req.header('x-real-ip'),
|
skip: (c) => !c.req.header('x-real-ip'),
|
||||||
keyGenerator: (c) => c.req.header('x-real-ip')!,
|
keyGenerator: (c) => c.req.header('x-real-ip')!,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue