heroku - 应用程序在本地环境中运行,但在 Heroku 上失败
问题描述
我的应用在我的 Cloud9 工作区上运行良好,但在 Heroku 上却不行。我已连接到 mLab 数据库。我也尝试过切换数据库,但它不起作用。
错误日志:
hacker8878:~/workspace/YelpCamp/v10 (master) $ heroku run node app.js
Running node app.js on ⬢ murmuring-brushlands-13115... up, run.5176 (Free)
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
The YelpCamp server has started
(node:4) UnhandledPromiseRejectionWarning: Error: URL malformed, cannot be parsed
at module.exports (/app/node_modules/mongodb/lib/url_parser.js:17:21)
at connect (/app/node_modules/mongodb/lib/mongo_client.js:880:3)
at connectOp (/app/node_modules/mongodb/lib/mongo_client.js:269:3)
at executeOperation (/app/node_modules/mongodb/lib/utils.js:420:24)
at MongoClient.connect (/app/node_modules/mongodb/lib/mongo_client.js:260:10)
at Promise (/app/node_modules/mongoose/lib/connection.js:427:12)
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:424:19)
at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:208:15)
at Object.<anonymous> (/app/app.js:19:10)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
(node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
解决方案
请参阅此相关问题。看起来您正在尝试将 Express 会话存储与 mongoose 一起使用,所以我猜您正在使用 connect-mongo。确保您没有在通话中输入错误的store
属性。express.session()
我还建议检查connect-mongodb-session作为 connect-mongo 的替代方案。开箱即用更容易,而且更不容易出错。
推荐阅读
- jakarta-ee - 带有 CDI 和现有 JAX-RS 服务的 Vaadin 12 PWA
- meteor - Meteor 1.8.0.2 npm 错误:找不到模块'createjs'
- java - 获取字符串字节以执行 XOR 检查的 Java 错误
- c# - 我的页面出现 404 错误。但是当我刷新页面时它可以正常工作
- swift - CollectionView 单元中的标签值在 reloadItems() 时与旧值重叠一毫秒
- angularjs - Access-Control-Allow-Origin 中的多个 ip 不起作用
- python - 如何获得经过训练的 CNN 模型某一层的输出 [Tensorflow]
- java - 如何正确使用多个边界?
- reactjs - 图像作为 Proptype 还是作为字符串从父级传递给子级?
- angular - 如何设置 matButton 活动(聚焦)角度?