Vercel/src/app/(isr)/photos/[photoId]/image/route.tsx
Sam Becker df11a86181 Init
2023-09-05 09:00:57 -05:00

43 lines
1.1 KiB
TypeScript

import PhotoOGImageResponse from '@/photo/image-response/PhotoOGImageResponse';
import { getPhoto } from '@/services/postgres';
import { IMAGE_OG_WIDTH, IMAGE_OG_HEIGHT } from '@/site';
import { FONT_FAMILY_IBM_PLEX_MONO, getIBMPlexMonoMedium } from '@/site/font';
import { ImageResponse } from '@vercel/og';
const DEBUG_CACHING: boolean = false;
export const runtime = 'edge';
export async function GET(request: Request, context: any) {
const photo = await getPhoto(context.params.photoId);
const fontData = await getIBMPlexMonoMedium();
return new ImageResponse(
(
<PhotoOGImageResponse
photo={photo}
requestOrPhotoPath={request}
width={IMAGE_OG_WIDTH}
height={IMAGE_OG_HEIGHT}
fontFamily={FONT_FAMILY_IBM_PLEX_MONO}
/>
),
{
width: IMAGE_OG_WIDTH,
height: IMAGE_OG_HEIGHT,
fonts: [
{
name: FONT_FAMILY_IBM_PLEX_MONO,
data: fontData,
weight: 500,
style: 'normal',
},
],
...!DEBUG_CACHING && {
headers: {
'Cache-Control': 's-maxage=3600, stale-while-revalidate',
},
},
},
);
}