Only request opengraph if api key is defined

This commit is contained in:
Shinigami92 2022-12-12 16:02:28 +01:00
parent 2c3e0253f6
commit a4eae9891b

View file

@ -40,12 +40,14 @@ export default defineEventHandler(async (event) => {
const html = await $fetch<string>(cardUrl)
ogImageUrl = extractOgImageUrl(html)
if (process.env.NUXT_OPENGRAPH_API) {
// If no og:image was found, try to get it from opengraph.io
if (!ogImageUrl) {
const response = await getOpenGraphClient().getSiteInfo(cardUrl)
ogImageUrl = response?.openGraph?.image?.url ?? ''
}
}
// eslint-disable-next-line no-console
console.log(JSON.stringify({ cardUrl, ogImageUrl }))