简体   繁体   English

将带有 ZCCADCDEDB567ABAE643E15DCF0974E503Z 的 Express 服务器部署到 Netlify

[英]Deploying Express server with Mongoose to Netlify

I am able to deploy an Express server with netlify using this tutorial: https://paulreaney.medium.com/deploy-express-js-on-netlify-91cfaea39591我可以使用本教程使用 netlify 部署 Express 服务器: https://paulreaney.medium.com/deploy-express-js-on-netlify-91cfaea39591

When I add Mongoose to the server I get a crash notification and a timeout.当我将 Mongoose 添加到服务器时,我收到崩溃通知和超时。

服务器超时

I then tried installing mongodb-client-encryption but same error.然后我尝试安装mongodb-client-encryption但同样的错误。

Is it possible to have an express server that calls a MongoDB collection hosted on Netlify?是否可以有一个快速服务器调用 Netlify 上托管的 MongoDB 集合?

If there is other information I can share to aid with this please tell me and I will!如果我可以分享其他信息来帮助解决这个问题,请告诉我,我会的!

Thanks Tim谢谢蒂姆

Edit: To clarify, when I run the express server on my local it works perfectly.编辑:澄清一下,当我在本地运行快速服务器时,它运行良好。

I figured it out, there were two issues, both causing the function calls to take more than 10 seconds so it was timing out.我想通了,有两个问题,都导致 function 调用需要超过 10 秒,所以它超时了。

The first issue was the simplest, I hadn't allowed any IP address to query the database on my MongoDB dashboard.第一个问题是最简单的,我不允许任何 IP 地址在我的 MongoDB 仪表板上查询数据库。

The second issue was I hadn't set my handler up properly to interact with asynchronous functions (which mongoose uses).第二个问题是我没有正确设置我的处理程序以与异步函数(mongoose 使用)交互。 Here is the code I used to fix it:这是我用来修复它的代码:

Before:前:

module.exports.handler = serverless(app);

After:后:

const handler = serverless(app);
module.exports.handler = async (event, context) => {
  const result = await handler(event, context);
  return result;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM