Skip to content

Commit 4162fce

Browse files
committedNov 27, 2024
Update rate limiting and cache control headers for improved performance and security
1 parent 86a405c commit 4162fce

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed
 

‎src/index.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function getErrorBadgeSVG(message: string) {
2323
async function rateLimit(c: any, next: () => Promise<any>) {
2424
const ip = c.req.raw.headers.get("cf-connecting-ip") || "unknown";
2525
const KEY_PREFIX = "ratelimit:";
26-
const LIMIT = 10;
27-
const WINDOW = 300;
26+
const LIMIT = 60;
27+
const WINDOW = 60;
2828

2929
try {
3030
const key = `${KEY_PREFIX}${ip}`;
@@ -327,11 +327,9 @@ app.get("/visitor-badge/:repo", async (c) => {
327327
return new Response(svg, {
328328
headers: {
329329
"Content-Type": "image/svg+xml; charset=utf-8",
330-
"Cache-Control": "public, max-age=60, s-maxage=60, stale-while-revalidate=300",
331-
"CDN-Cache-Control": "max-age=60",
332-
"Surrogate-Control": "max-age=60",
333-
"Edge-Control": "max-age=60",
334-
"Age": "0",
330+
"Cache-Control": "no-cache, no-store, must-revalidate",
331+
"Pragma": "no-cache",
332+
"Expires": "0",
335333
"Vary": "Accept-Encoding",
336334
"ETag": `"${count}"`
337335
},
@@ -468,8 +466,9 @@ app.get("/ai-badge", async (c) => {
468466
return new Response(svg, {
469467
headers: {
470468
"Content-Type": "image/svg+xml; charset=utf-8",
471-
"Cache-Control": "public, max-age=1800",
472-
"CDN-Cache-Control": "public, max-age=1800",
469+
"Cache-Control": "no-cache, no-store, must-revalidate",
470+
"Pragma": "no-cache",
471+
"Expires": "0"
473472
},
474473
});
475474

0 commit comments

Comments
 (0)