You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

生产环境使用getServerSideProps时遇Fetch请求超时错误求助

getServerSideProps生产环境Fetch请求超时问题

我使用getServerSideProps为页面填充SEO相关数据,该功能在开发环境运行正常,但在生产环境中出现Fetch请求超时错误,报错信息如下:

FetchError: request to API failed, reason: connect ETIMEDOUT

// lib/fetchData.js

export const GetData = async (id) => {
    try {
        const res = await fetch(`api?id=${id}`, {
            method: 'Get',
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json"
            },
            agent,
        })
        const data = await res.json()
        return data

    } catch (error) {
        console.log(error);
    }
}

// 在 /myPage 页面中
export async function getServerSideProps({ query }) {
    const data = await GetData(query.DetailedCampaign)
    console.log('data', data);
    return { props: { metaDetails: await data?.Data[0] } }
}

编辑补充:我也尝试了以下实现方式,依然遇到相同问题——开发环境正常,生产环境超时:

export async function getServerSideProps({ query }) {
    try {
        const response = await fetch(`https://internalApi?id=${query.id}`, {
            method: 'Get',
            agent: httpsAgent,
            headers: {
                "Content-Type": "application/json",
            },
        });

        const data = await response.json();

        return { props: { metaDetails: data?.Data[0] } };
    } catch (error) {
        console.error(error);
        return { props: { metaDetails: null } };
    }
}

内容的提问来源于stack exchange,提问作者eslam elameen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 06:44:57