Make data static endpoints more resilient
This commit is contained in:
parent
279454b288
commit
7373a1b1f9
@ -11,7 +11,7 @@ export async function GET() {
|
||||
const photos = await getPhotosCached({
|
||||
limit: FEED_PHOTO_REQUEST_LIMIT,
|
||||
sortBy: 'createdAt',
|
||||
});
|
||||
}).catch(() => []);
|
||||
return Response.json(formatFeedJson(photos));
|
||||
} else {
|
||||
return new Response('Feeds disabled', { status: 404 });
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { getPhotosCached } from '@/photo/cache';
|
||||
import { SITE_FEEDS_ENABLED } from '@/app/config';
|
||||
import { FEED_PHOTO_REQUEST_LIMIT } from '@/feed';
|
||||
import { formatFeedRss } from '@/feed/rss';
|
||||
import { formatFeedRssXml } from '@/feed/rss';
|
||||
|
||||
// Cache for 24 hours
|
||||
export const revalidate = 86_400;
|
||||
@ -11,10 +11,9 @@ export async function GET() {
|
||||
const photos = await getPhotosCached({
|
||||
limit: FEED_PHOTO_REQUEST_LIMIT,
|
||||
sortBy: 'createdAt',
|
||||
});
|
||||
|
||||
}).catch(() => []);
|
||||
return new Response(
|
||||
formatFeedRss(photos),
|
||||
formatFeedRssXml(photos),
|
||||
{ headers: { 'Content-Type': 'text/xml' } },
|
||||
);
|
||||
} else {
|
||||
|
||||
@ -34,8 +34,15 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
},
|
||||
photos,
|
||||
] = await Promise.all([
|
||||
getDataForCategoriesCached(),
|
||||
getPhotoIdsAndUpdatedAt(),
|
||||
getDataForCategoriesCached().catch(() => ({
|
||||
cameras: [],
|
||||
lenses: [],
|
||||
tags: [],
|
||||
recipes: [],
|
||||
films: [],
|
||||
focalLengths: [],
|
||||
})),
|
||||
getPhotoIdsAndUpdatedAt().catch(() => []),
|
||||
]);
|
||||
|
||||
const lastModifiedSite = [
|
||||
|
||||
@ -57,7 +57,7 @@ const feedPhotoToXml = (photo: FeedPhotoRss): string => {
|
||||
</item>`;
|
||||
};
|
||||
|
||||
export const formatFeedRss = (photos: Photo[]) =>
|
||||
export const formatFeedRssXml = (photos: Photo[]) =>
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0"
|
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user