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