import { ImageResponse } from 'next/og';
import { NextRequest } from 'next/server';
export const runtime = 'edge';
export async function GET(req: NextRequest) {
try {
const { searchParams } = new URL(req.url);
// ?title=
const hasTitle = searchParams.has('title');
const title = hasTitle
? searchParams.get('title')?.slice(0, 100)
: 'My default title';
return new ImageResponse(
(
),
{
width: 1200,
height: 630,
}
);
} catch (error: unknown) {
console.log(`${error instanceof Error ? error.message : 'Unknown error'}`);
return new Response(`Failed to generate the image`, {
status: 500,
});
}
}
// Default export za koriĊĦtenje u app/search/[collection]/opengraph-image.tsx
export default async function OpengraphImage({ title = 'My default title' }: { title?: string }) {
return new ImageResponse(
(
),
{
width: 1200,
height: 630,
}
);
}