我将 Nextjs 应用程序部署到 Vercel,但我的 api 调用失败,响应为 500,即使它在 localhost 上运行也是如此。我可以使用 获得初始负载getStaticProps,所以我相信与数据库的连接是可以的。
我的getStaticPaths功能正常工作如下所示:
export async function getStaticProps() {
dbConnect();
const properties = await Property.find({
deletedAt: { $exists: false },
archivedAt: { $exists: false },
})
.sort({ refreshed: -1 })
.limit(itemsPerPage);
const propertiesCount = await Property.countDocuments(
{ deletedAt: { $exists: false }, archivedAt: { $exists: false } },
{ limit: 100 }
);
const pagesCount = Math.ceil(propertiesCount / itemsPerPage);
return {
props: {
fetchedProperties: properties.map((property) => propertyToJson(property)),
pagesCount: pagesCount, …Run Code Online (Sandbox Code Playgroud)