Vercel/app/feed.json/route.ts
2025-06-12 20:35:38 -05:00

29 lines
675 B
TypeScript

import { getPhotosCached } from '@/photo/cache';
import {
BASE_URL,
SITE_FEEDS_ENABLED,
META_TITLE,
} from '@/app/config';
import { FEED_PHOTO_REQUEST_LIMIT, formatPhotoForFeedJson } from '@/app/feed';
// Cache for 24 hours
export const revalidate = 86_400;
export async function GET() {
if (SITE_FEEDS_ENABLED) {
const photos = await getPhotosCached({
limit: FEED_PHOTO_REQUEST_LIMIT,
sortBy: 'createdAt',
});
return Response.json({
meta: {
title: META_TITLE,
url: BASE_URL,
},
photos: photos.map(formatPhotoForFeedJson),
});
} else {
return new Response('Feed disabled', { status: 404 });
}
}