feat: add cache control

This commit is contained in:
shinya
2025-06-19 12:45:46 +08:00
parent da46031ae6
commit 660b51d9bd
5 changed files with 48 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
import { NextResponse } from 'next/server';
import { getCacheTime } from '@/lib/config';
interface DoubanItem {
title: string;
poster: string;
@@ -110,7 +112,12 @@ export async function GET(request: Request) {
list: list,
};
return NextResponse.json(response);
const cacheTime = getCacheTime();
return NextResponse.json(response, {
headers: {
'Cache-Control': `public, max-age=${cacheTime}`,
},
});
} catch (error) {
return NextResponse.json(
{ error: '获取豆瓣数据失败', details: (error as Error).message },
@@ -173,7 +180,12 @@ function handleTop250(pageStart: number) {
list: movies,
};
return NextResponse.json(apiResponse);
const cacheTime = getCacheTime();
return NextResponse.json(apiResponse, {
headers: {
'Cache-Control': `public, max-age=${cacheTime}`,
},
});
})
.catch((error) => {
clearTimeout(timeoutId);