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