From ba21a343a55c6868f9a6acf3e676d7c9148f2462 Mon Sep 17 00:00:00 2001 From: shinya Date: Sat, 26 Jul 2025 22:22:19 +0800 Subject: [PATCH] feat: add api cdn cache control --- src/app/api/detail/route.ts | 4 +++- src/app/api/douban/categories/route.ts | 4 +++- src/app/api/douban/route.ts | 8 ++++++-- src/app/api/search/one/route.ts | 8 ++++++-- src/app/api/search/resources/route.ts | 4 +++- src/app/api/search/route.ts | 8 ++++++-- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/app/api/detail/route.ts b/src/app/api/detail/route.ts index 29b7883..6d3c71b 100644 --- a/src/app/api/detail/route.ts +++ b/src/app/api/detail/route.ts @@ -31,7 +31,9 @@ export async function GET(request: Request) { return NextResponse.json(result, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, }); } catch (error) { diff --git a/src/app/api/douban/categories/route.ts b/src/app/api/douban/categories/route.ts index cf2ac87..ea85bc1 100644 --- a/src/app/api/douban/categories/route.ts +++ b/src/app/api/douban/categories/route.ts @@ -119,7 +119,9 @@ export async function GET(request: Request) { const cacheTime = await getCacheTime(); return NextResponse.json(response, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, }); } catch (error) { diff --git a/src/app/api/douban/route.ts b/src/app/api/douban/route.ts index bbe4a05..e9eee27 100644 --- a/src/app/api/douban/route.ts +++ b/src/app/api/douban/route.ts @@ -112,7 +112,9 @@ export async function GET(request: Request) { const cacheTime = await getCacheTime(); return NextResponse.json(response, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, }); } catch (error) { @@ -185,7 +187,9 @@ function handleTop250(pageStart: number) { const cacheTime = await getCacheTime(); return NextResponse.json(apiResponse, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, }); }) diff --git a/src/app/api/search/one/route.ts b/src/app/api/search/one/route.ts index 95e88a0..8af2506 100644 --- a/src/app/api/search/one/route.ts +++ b/src/app/api/search/one/route.ts @@ -17,7 +17,9 @@ export async function GET(request: Request) { { result: null, error: '缺少必要参数: q 或 resourceId' }, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, } ); @@ -55,7 +57,9 @@ export async function GET(request: Request) { { results: result }, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, } ); diff --git a/src/app/api/search/resources/route.ts b/src/app/api/search/resources/route.ts index 59ba776..fc351fd 100644 --- a/src/app/api/search/resources/route.ts +++ b/src/app/api/search/resources/route.ts @@ -12,7 +12,9 @@ export async function GET() { return NextResponse.json(apiSites, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, }); } catch (error) { diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index 1223604..a9c64c3 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -15,7 +15,9 @@ export async function GET(request: Request) { { results: [] }, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, } ); @@ -33,7 +35,9 @@ export async function GET(request: Request) { { results: flattenedResults }, { headers: { - 'Cache-Control': `public, max-age=${cacheTime}`, + 'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`, + 'CDN-Cache-Control': `public, s-maxage=${cacheTime}`, + 'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`, }, } );