Skip to content

Commit 77cd06b

Browse files
authored
search: add cache-control headers (#233)
* search: add cache-control headers * fix tests
1 parent 5e39120 commit 77cd06b

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

src/app/api/news/__tests__/route.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("GET /api/news", () => {
1616
const res = await GET(req);
1717
expect(res.status).toBe(200);
1818
expect(res.headers.get("Cache-Control")).toBe(
19-
"public, max-age=3600, stale-while-revalidate=60"
19+
"public, max-age=14400, stale-while-revalidate=60"
2020
);
2121
const data = await res.json();
2222
expect(data).toBeDefined();

src/app/api/news/byTag/__tests__/route.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("GET /api/news/byTag", () => {
2424
const res = await GET(req);
2525
expect(res.status).toBe(200);
2626
expect(res.headers.get("Cache-Control")).toBe(
27-
"public, max-age=3600, stale-while-revalidate=60"
27+
"public, max-age=14400, stale-while-revalidate=60"
2828
);
2929
const data = await res.json();
3030
expect(data).toBeDefined();

src/app/api/news/byTag/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function GET(req: NextRequest) {
1313
const news = getNewsByTag(tag, { numPosts, page });
1414
return Response.json(news, {
1515
headers: {
16-
"Cache-Control": "public, max-age=3600, stale-while-revalidate=60",
16+
"Cache-Control": "public, max-age=14400, stale-while-revalidate=60",
1717
},
1818
});
1919
} catch {

src/app/api/news/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function GET(req: NextRequest) {
1010
const news = await getNews({ numPosts, page, includeEF });
1111
return Response.json(news, {
1212
headers: {
13-
"Cache-Control": "public, max-age=3600, stale-while-revalidate=60",
13+
"Cache-Control": "public, max-age=14400, stale-while-revalidate=60",
1414
},
1515
});
1616
} catch {

src/app/api/search/route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import {
77
export async function GET(req: NextRequest) {
88
const { searchParams } = new URL(req.url!);
99
const query = searchParams.get("q") || "";
10-
if (query.length < 2) return NextResponse.json([]);
10+
if (query.length < 2) {
11+
return NextResponse.json([], {
12+
headers: {
13+
"Cache-Control": "public, max-age=14400, stale-while-revalidate=60",
14+
},
15+
});
16+
}
1117

1218
const paths = await getAllAsciidocPaths();
1319
const results = [];
@@ -28,5 +34,9 @@ export async function GET(req: NextRequest) {
2834
});
2935
}
3036
}
31-
return NextResponse.json(results);
37+
return NextResponse.json(results, {
38+
headers: {
39+
"Cache-Control": "public, max-age=14400, stale-while-revalidate=60",
40+
},
41+
});
3242
}

0 commit comments

Comments
 (0)