在 Heroku 上提升风帆应用程序失败
Lifting a sails app on Heroku fails
我无法在 Heroku 的生产环境中提升 Sails api 应用程序以连接 mongolab 数据库。这在本地设置中 运行 时效果很好。 Heroku 日志显示以下内容...
`
/app/node_modules/mongodb/lib/server.js:235
process.nextTick(function() { throw err; })
^
TypeError: Cannot read property 'close' of undefined
at /app/node_modules/sails-mongo/lib/adapter.js:138:13
at /app/node_modules/sails-mongo/node_modules/async/lib/async.js:187:20
at /app/node_modules/sails-mongo/node_modules/async/lib/async.js:239:13
at _arrayEach (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:91:13)
at _each (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:82:13)
at Object.async.forEachOf.async.eachOf (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:238:9)
at Object.async.forEach.async.each (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:215:22)
at Object.module.exports.adapter.teardown (/app/node_modules/sails-mongo/lib/adapter.js:137:22)
at /app/node_modules/sails/lib/hooks/orm/index.js:244:19
at /app/node_modules/async/lib/async.js:122:13
at _each (/app/node_modules/async/lib/async.js:46:13)
at Object.async.each (/app/node_modules/async/lib/async.js:121:9)
at Sails.hook.teardown (/app/node_modules/sails/lib/hooks/orm/index.js:241:13)
at Sails.g (events.js:260:16)
at emitNone (events.js:67:13)
at Sails.emit (events.js:166:7)
`
运行 风帆版本 0.11.2
Sails-mongo 版本 0.11.4
已添加并验证process.env个变量
connection.js
`
mongodb: {
adapter: 'sails-mongo',
url : process.env.CONNECTION_URL,
host: process.env.DB_HOST,
port: process.env.PORT_NR,
user: proces.env.USER,
password: process.env.PASSWORD,
database: process.env.DB
},
`
env/production.js
`
connections : {
mongoLive: {
adapter: 'sails-mongo',
url : process.env.CONNECTION_URL
}
},
models: {
connection: 'mongoLive'
},
`
development.js
`
connections : {
mongoDev: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
database: 'threads_db'
}
},
models: {
connection: 'mongoDev'
}
`
过程文件
`
web: npm start
`
package.json
`
"scripts": {
"debug": "node debug app.js",
"start": "sails lift"
},
`
models.js 已设置为
`
connection: 'mongodb',
`
因此,运行 这在本地可以很好地连接到本地 mongo 数据库和远程 mongolab 数据库,但部署到 Heroku 失败。在我看来,我在设置中遗漏了一些东西。对此表示感谢。
已知错误。查看 https://github.com/balderdashy/sails-mongo/issues/352
在发布之前,您可能需要 npm install sails-mongo#master --save
。
我使用 sails-mongo 的主版本解决了这个问题。
package.json
"sails": "git+https://github.com/balderdashy/sails.git"
然后部署到 heroku 后用
重新启动测功机
`heroku ps:scale web=1`
如果在 heroku 中部署后接受的答案不起作用,请尝试更改节点 js、sails-mongo 版本以及 sails 并检查。
将版本更改为以下后对我有用:
1.nodejs - 14.15.1
2.sails - ^1.5.2
3.sails-mongo - ^2.0.0
我无法在 Heroku 的生产环境中提升 Sails api 应用程序以连接 mongolab 数据库。这在本地设置中 运行 时效果很好。 Heroku 日志显示以下内容...
`
/app/node_modules/mongodb/lib/server.js:235
process.nextTick(function() { throw err; })
^
TypeError: Cannot read property 'close' of undefined
at /app/node_modules/sails-mongo/lib/adapter.js:138:13
at /app/node_modules/sails-mongo/node_modules/async/lib/async.js:187:20
at /app/node_modules/sails-mongo/node_modules/async/lib/async.js:239:13
at _arrayEach (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:91:13)
at _each (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:82:13)
at Object.async.forEachOf.async.eachOf (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:238:9)
at Object.async.forEach.async.each (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:215:22)
at Object.module.exports.adapter.teardown (/app/node_modules/sails-mongo/lib/adapter.js:137:22)
at /app/node_modules/sails/lib/hooks/orm/index.js:244:19
at /app/node_modules/async/lib/async.js:122:13
at _each (/app/node_modules/async/lib/async.js:46:13)
at Object.async.each (/app/node_modules/async/lib/async.js:121:9)
at Sails.hook.teardown (/app/node_modules/sails/lib/hooks/orm/index.js:241:13)
at Sails.g (events.js:260:16)
at emitNone (events.js:67:13)
at Sails.emit (events.js:166:7)
`
运行 风帆版本 0.11.2
Sails-mongo 版本 0.11.4
已添加并验证process.env个变量
connection.js
`
mongodb: {
adapter: 'sails-mongo',
url : process.env.CONNECTION_URL,
host: process.env.DB_HOST,
port: process.env.PORT_NR,
user: proces.env.USER,
password: process.env.PASSWORD,
database: process.env.DB
},
` env/production.js
`
connections : {
mongoLive: {
adapter: 'sails-mongo',
url : process.env.CONNECTION_URL
}
},
models: {
connection: 'mongoLive'
},
`
development.js
`
connections : {
mongoDev: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
database: 'threads_db'
}
},
models: {
connection: 'mongoDev'
}
`
过程文件
`
web: npm start
`
package.json
`
"scripts": {
"debug": "node debug app.js",
"start": "sails lift"
},
`
models.js 已设置为
`
connection: 'mongodb',
`
因此,运行 这在本地可以很好地连接到本地 mongo 数据库和远程 mongolab 数据库,但部署到 Heroku 失败。在我看来,我在设置中遗漏了一些东西。对此表示感谢。
已知错误。查看 https://github.com/balderdashy/sails-mongo/issues/352
在发布之前,您可能需要 npm install sails-mongo#master --save
。
我使用 sails-mongo 的主版本解决了这个问题。
package.json
"sails": "git+https://github.com/balderdashy/sails.git"
然后部署到 heroku 后用
重新启动测功机`heroku ps:scale web=1`
如果在 heroku 中部署后接受的答案不起作用,请尝试更改节点 js、sails-mongo 版本以及 sails 并检查。
将版本更改为以下后对我有用:
1.nodejs - 14.15.1
2.sails - ^1.5.2
3.sails-mongo - ^2.0.0