32 lines
983 B
TypeScript
32 lines
983 B
TypeScript
import { NextResponse } from 'next/server';
|
|
|
|
import { getAvailableApiSites, getCacheTime } from '@/lib/config';
|
|
import { addCorsHeaders, handleOptionsRequest } from '@/lib/cors';
|
|
|
|
export const runtime = 'edge';
|
|
|
|
// 处理OPTIONS预检请求(OrionTV客户端需要)
|
|
export async function OPTIONS() {
|
|
return handleOptionsRequest();
|
|
}
|
|
|
|
// OrionTV 兼容接口
|
|
export async function GET() {
|
|
try {
|
|
const apiSites = await getAvailableApiSites();
|
|
const cacheTime = await getCacheTime();
|
|
|
|
const response = NextResponse.json(apiSites, {
|
|
headers: {
|
|
'Cache-Control': `public, max-age=${cacheTime}, s-maxage=${cacheTime}`,
|
|
'CDN-Cache-Control': `public, s-maxage=${cacheTime}`,
|
|
'Vercel-CDN-Cache-Control': `public, s-maxage=${cacheTime}`,
|
|
},
|
|
});
|
|
return addCorsHeaders(response);
|
|
} catch (error) {
|
|
const response = NextResponse.json({ error: '获取资源失败' }, { status: 500 });
|
|
return addCorsHeaders(response);
|
|
}
|
|
}
|