你是我在这里的最后机会。因此,我使用 generator-sql-fullstack 包构建了一个项目,并尝试将其部署到 heroku。
不幸的是,我无法连接到 Heroku 数据库,因为我收到错误 R10。
我尝试了不同的方法来通过 sequelize 连接到 postgres - 它们都不起作用。主要是使其与 ssl 兼容,但它仍然无法连接(或者我可能使用错误)
项目在本地运行良好,应用程序构建也没有任何错误。
请查看用于连接的 Heroku 日志和主要文件。希望你能在这里帮助我。谢谢你。
$ heroku logs
2016-04-18T21:27:36.994697+00:00 app[web.1]: > node server/app.js
2016-04-18T21:27:36.994705+00:00 app[web.1]:
2016-04-18T21:27:37.784886+00:00 app[web.1]: Express server listening on 55648, in production mode
2016-04-18T21:28:34.891786+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-04-18T21:28:34.891786+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-04-18T21:28:35.750471+00:00 heroku[web.1]: Process exited with status 137
/server/config/environment/production.js
module.exports = {
database: 'DBNAME',
username: 'DBUSERNAME',
password: 'DBPASSWORD',
sql: {
host: 'DBHOST',
port: process.env.PORT || '5432',
dialect: 'postgres',
dialectOptions: {
ssl: true
}
}
};
/server/api/index.js
var sequelize = new Sequelize(config.database, config.username, config.password, config.sql);
除此之外,服务器端没有任何内容。
我的猜测是我错误地使用了 Sequelize,但我遵循了文档(为 heroku 调整 SSL)。
如果您想查看更多配置文件,请告诉我。
感谢您的任何意见!
最佳答案
这:
var sequelize = new Sequelize(process.env.DATABASE_URL);
应该足以连接到 Heroku 的 Postgres。您可以在 Heroku Dashboard -> YourApp -> Settings -> Config Variables 中检查 DATABASE_URL。您还可以从该字符串中获取 db 凭据,但您不需要这样做。
process.env.PORT 不是数据库端口,而是您应该启动服务器的端口(因此 Heroku 可以执行其内部路由),例如:
server.listen(process.env.PORT || 5432)
所以你的配置文件应该是这样的:
module.exports = {
port: process.env.PORT || 5432,
database: {
uri: process.env.DATABASE_URL
}
};
并连接到数据库:
var sequelize = new Sequelize(config.database.uri);
关于angularjs - 使用 generator-sql-fullstack 在 heroku 上拒绝连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36708758/