Vercel/src/app/api/route.ts
2023-10-07 14:29:05 -05:00

23 lines
562 B
TypeScript

import { getPhotosCached } from '@/cache';
import { API_PHOTO_REQUEST_LIMIT, formatPhotoForApi } from '@/site/api';
import {
BASE_URL,
PUBLIC_API_ENABLED,
SITE_TITLE,
} from '@/site/config';
export async function GET() {
if (PUBLIC_API_ENABLED) {
const photos = await getPhotosCached({ limit: API_PHOTO_REQUEST_LIMIT });
return Response.json({
meta: {
title: SITE_TITLE,
url: BASE_URL,
},
photos: photos.map(formatPhotoForApi),
});
} else {
return Response.json({ message: 'API is disabled' });
}
}