import { ImageResponse } from '@vercel/og'
import { NextRequest } from 'next/server'
export const config = {
runtime: 'experimental-edge',
}
export default function handler(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(
(
{/* eslint-disable-next-line @next/next/no-img-element */}
{title}
),
{
width: 1200,
height: 630,
}
)
} catch (e: any) {
console.log(`${e.message}`)
return new Response(`Failed to generate the image`, {
status: 500,
})
}
}