当我在开发中运行它时,我的node.js应用程序运行良好,但是当我尝试在heroku上打开它时,它崩溃并显示错误代码H10和503状态代码。以下是控制服务器(/app/index.js)的代码:
const listen = (port) => {
return new Promise((resolve, reject) => {
return resolve(app.listen(port));
});
};
exports.up = (justBackend) => {
return db.migrate.latest([ENV])
.then(() => {
return db.migrate.currentVersion();
})
.then((val) => {
console.log('Done running latest migration:', val);
return listen(process.env.PORT || 3000);
})
.then((server) => {
console.log(`Listening on port ${process.env.PORT} || 3000...`);
return server
});
};
起初,我只是将端口设置为3000,所以我添加了heroku可以动态设置端口的部分,但仍然出现相同的错误。也不确定该错误是否可能是由于我的package.json中的某物引起的,所以这也是:
{
"name": "hand-tracker",
"version": "1.0.0",
"description": "A tool to track common trends in the poker hands I win and
lose",
"main": "index.js",
"scripts": {
"test": "export NODE_ENV=testing; mocha --recursive -R mocha-multi --
reporter-options spec=-,json=.results.json",
"start": "export NODE_ENV=development; node server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AdamT213/hand-tracker.git"
},
"author": "Adam Tropp",
"license": "MIT",
"bugs": {
"url": "https://github.com/AdamT213/hand-tracker/issues"
},
"homepage": "https://github.com/AdamT213/hand-tracker#readme",
"devDependencies": {
"body-parser": "^1.18.3",
"chai": "^4.1.2",
"express": "^4.16.3",
"jsdom": "^11.11.0",
"lodash": "^4.17.10",
"mocha": "^5.2.0",
"mocha-jsdom": "^2.0.0",
"mocha-multi": "^1.0.1",
"supertest": "^3.1.0"
},
"dependencies": {
"bookshelf": "^0.13.3",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.4.3",
"express-session": "^1.15.6",
"knex": "^0.15.1",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"pg": "^7.4.3"
}
}
**编辑:我在package.json中添加了一个heroku postbuild脚本,该脚本在生产环境中安装了dev依赖项,但是仍然出现相同的错误。当我运行heroku restart时,出现错误消息
2018-07-29T21:48:38.419242 + 00:00 app [web.1]:在环境中运行:开发 2018-07-29T21:48:38.575292 + 00:00 app [web.1]:未处理的拒绝错误:连接ECONNREFUSED 127.0.0.1:5432
我是否需要使启动脚本在生产环境中运行而不是在开发环境中运行?