next-api-og-image 在开发中工作,但不在生产中使用 netlify

问题描述 投票:0回答:0

我想为我博客的每篇文章创建动态社交图像。 我正在用

Next.js
建立网站,我看到这个插件(
next-api-og-image
)来创建动态图像。

我试过了,在开发过程中一切都很好(localhost:3000/api/og?title=sometext&type=news),我能够创建图像但是当我通过

Netlify
将网站部署到生产环境时,当我去图片 URL,它返回错误“
Internal Server Error
”。

我在网上搜索,但找不到任何东西。

这是我的代码

// /pages/api/og.js

import { withOGImage } from 'next-api-og-image'

export default withOGImage({
    template: {
        react: ({ title, type }) =>
            <div style={{
                height: '100%',
                width: '100%',
                display: 'flex',
                flexDirection: 'column',
                alignItems: 'left',
                justifyContent: 'center',
                padding: '5rem 3rem',
                backgroundColor: '#4D0F0009',
            }}>
                [... other html code to style the image]
            </div>
    },
    strategy: 'query',
    cacheControl: 'max-age 60, must-revalidate',
    type: 'jpeg',
    quality: 90,
    width: 1200,
    height: 675
})

在我要创建图像的页面

// /pages/articles/[id].js

<NextSeo
   openGraph={{
      url: 'blog.leonifrancesco.com/articles/' + data.id,
      images: [{
         url: 'https://blog.leonifrancesco.com/api/og?title=' + data.title + '&type=' + data.category,
         alt: data.title
    }]
  }}
/>

在首页我不需要创建自定义图像,所以有一个静态图像 url。

也许我需要做一些事情才能部署 og API。

目前我做

yarn build
.

javascript reactjs next.js netlify dynamic-image-generation
© www.soinside.com 2019 - 2025. All rights reserved.