【发布时间】:2022-08-07 22:08:15
【问题描述】:
我最近将我的 express 项目部署到vercel.com。但是由于某种原因,我在发出 HTTP 请求时经常会收到 500 错误,例如请求页面或请求图像(这里是链接,您可以自己查看wowcutegift.com)。
比如我可以得到一个错误500,然后我刷新页面就没有这个错误了,然后我再次刷新它又出现了。
[GET] /
js:15:10)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) {
reason: TopologyDescription {
type: \'ReplicaSetNoPrimary\',
servers: Map(3) {
\'cluster0-shard-00-00.admjq.mongodb.net:27017\' => [ServerDescription],
\'cluster0-shard-00-01.admjq.mongodb.net:27017\' => [ServerDescription],
\'cluster0-shard-00-02.admjq.mongodb.net:27017\' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: \'atlas-wz86q8-shard-0\',
logicalSessionTimeoutMinutes: undefined
}
}
2022-03-24T09:25:22.973Z d5a670eb-5b1f-4d0d-8886-056d2fe8fe72 ERROR Unhandled Promise Rejection {\"errorType\":\"Runtime.UnhandledPromiseRejection\",\"errorMessage\":\"MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you\'re trying to access the database from an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/\",\"reason\":{\"errorType\":\"MongooseServerSelectionError\",\"errorMessage\":\"Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you\'re trying to access the database from an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/\",\"message\":\"Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you\'re trying to access the database from an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/\",\"reason\":{\"type\":\"ReplicaSetNoPrimary\",\"servers\":{},\"stale\":false,\"compatible\":true,\"heartbeatFrequencyMS\":10000,\"localThresholdMS\":15,\"setName\":\"atlas-wz86q8-shard-0\"},\"stack\":[\"MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you\'re trying to access the database from an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/\",\" at NativeConnection.Connection.openUri (/var/task/node_modules/mongoose/lib/connection.js:807:32)\",\" at /var/task/node_modules/mongoose/lib/index.js:340:10\",\" at /var/task/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5\",\" at new Promise (<anonymous>)\",\" at promiseOrCallback (/var/task/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)\",\" at Mongoose._promiseOrCallback (/var/task/node_modules/mongoose/lib/index.js:1140:10)\",\" at Mongoose.connect (/var/task/node_modules/mongoose/lib/index.js:339:20)\",\" at Object.<anonymous> (/var/task/index.js:15:10)\",\" at Module._compile (internal/modules/cjs/loader.js:1085:14)\",\" at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)\"]},\"promise\":{},\"stack\":[\"Runtime.UnhandledPromiseRejection: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you\'re trying to access the database from an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/\",\" at process.<anonymous> (/var/runtime/index.js:35:15)\",\" at process.emit (events.js:412:35)\",\" at processPromiseRejections (internal/process/promises.js:245:33)\",\" at processTicksAndRejections (internal/process/task_queues.js:96:32)\"]}
[ERROR] [1648113922974] LAMBDA_RUNTIME Failed to post handler success response. HTTP response code: 400.
RequestId: 807a69b0-c3c4-4ba3-ac2d-4b1dd364a152 Error: Runtime exited with error: exit status 128
Runtime.ExitError
还有这条线
One common reason is that you\'re trying to access the database from an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
我将服务器的 IP 添加到白名单中,还尝试通过添加 0.0.0.0 来打开所有 IP 的访问权限,但仍然没有帮助。
如果有人遇到过这个问题,请告诉我。也许是因为我有一个免费版本的 MongoDB 或 vercel。我曾经在 Heroku 上有一个应用程序,没有遇到过这样的问题,尽管数据库是相同的并且是免费的。
-
您是否找到任何解决此错误的方法?我也有这个,它大部分时间都可以正常工作,但随机失败并出现这个 MongooseServerSelectionError 错误:(
-
杰里米,我没有找到解决方案。我已经切换到heroku。您可以写信给支持,但您会等待很长时间才能得到答复,使用另一台服务器会更容易。
标签: javascript node.js mongodb express vercel