a tool for shared writing and social publishing
298
fork

Configure Feed

Select the types of activity you want to include in your feed.

at bd92da54d372a73b661da0cf4e1ab791020c81ec 30 lines 1.1 kB view raw
1import { headers } from "next/headers"; 2 3export async function getMicroLinkOgImage( 4 path: string, 5 options?: { width?: number; height?: number; deviceScaleFactor?: number }, 6) { 7 const headersList = await headers(); 8 const hostname = headersList.get("x-forwarded-host"); 9 let protocol = headersList.get("x-forwarded-proto"); 10 let full_path = `${protocol}://${hostname}${path}`; 11 let response = await fetch( 12 `https://pro.microlink.io/?url=${encodeURIComponent(full_path)}&screenshot=true&viewport.width=${options?.width || 1400}&viewport.height=${options?.height || 733}&viewport.deviceScaleFactor=${options?.deviceScaleFactor || 1}&meta=false&embed=screenshot.url&force=true`, 13 { 14 headers: { 15 "x-api-key": process.env.MICROLINK_API_KEY!, 16 }, 17 next: { 18 revalidate: 600, 19 }, 20 }, 21 ); 22 const clonedResponse = response.clone(); 23 if (clonedResponse.status == 200) 24 clonedResponse.headers.set( 25 "CDN-Cache-Control", 26 "s-maxage=600, stale-while-revalidate=3600", 27 ); 28 29 return clonedResponse; 30}