这是我的 getServerSideProps 函数
export async function getServerSideProps({ params }) {
const data = await fetchData(`${API_BASE_URL}/api/v1/products/single/${params.slug}`);
return {
props: {
data,
},
};
}
当我使用 npm run dev
运行该代码时,该代码在开发阶段工作得非常好,它也可以获取数据。但是,当我在 vercel 上部署它时,它不会被调用。
这是我的构建结果:
Page Size First Load JS
┌ λ / 46.6 kB 245 kB
├ └ css/96d23e185e0bacaa66ee.css 4.45 kB
├ /_app 0 B 145 kB
├ λ /404 3.03 kB 148 kB
├ λ /api/hello 0 B 145 kB
├ λ /checkout 26.5 kB 207 kB
├ λ /login 11.1 kB 192 kB
└ λ /product/[slug] 10.7 kB 209 kB
+ First Load JS shared by all 145 kB
├ chunks/119e91bca4bfe5d8214256763b9bb4234979d76c.2d6ece.js 4.36 kB
├ chunks/4bc680447288648ecb1d62367bf21bb5dec77e78.ea61ed.js 27.5 kB
├ chunks/71247caf95475e3ea7f9a0f8a30beb258b23d005.a07d59.js 24.5 kB
├ chunks/commons.e0e970.js 13.8 kB
├ chunks/framework.33edf2.js 42.3 kB
├ chunks/main.87ce23.js 6.95 kB
├ chunks/pages/_app.79151a.js 23.9 kB
├ chunks/webpack.fb3cf7.js 1.83 kB
└ css/faaceae07142f5d6ab29.css 1.14 kB
λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
(ISR) incremental static regeneration (uses revalidate in getStaticProps)