我无法在Heruko上部署此应用,但可以在本地运行

时间:2019-12-25 15:11:56

标签: node.js heroku oauth-2.0

NodeJS应用程序在本地运行,但是无法在Heroku上部署它。 我尝试部署的应用是here。 (这是一个执行Oauth2的应用程序,但Oauth2并不是我的问题)。
在安装应用程序并使其在本地运行时,我在根目录中执行“ $ npm install”,将cd插入oauth2example,再次键入“ $ npm install”,然后输入“ $ node app.js”,它将在端口3000本地启动该应用程序

在部署到Heroku之前,我将其放在根package.json中,以复制为使应用程序在本地运行而进行的操作。我怀疑我的问题在这里。
(在开始时,您会注意到它只有“节点”。当我有“节点app.js”时,日志显示“找不到app / app.js”。)

"scripts": {
    "start": "node ",
    "test": "mocha",
    "client": "npm start --prefix oauth2example",
    "heroku-postbuild": "npm install && npm install --prefix oauth2example"
},

在第53和74行的'oauth2example / app.js'中,我将网址从...更改为

http://localhost:' + port + '/...'

'https://<app_name>.herokuapp.com/...'

我还在oauth2example / views / intuit.ejs文件中以相同的方式更改了链接,并尝试部署每个变体以使所有链接保持相同或不变。

您会在oauth2example / app.js的第4行注意到端口是

var port = process.env.PORT || 3000;  

我相信Heroku需要'process.env.PORT'。我不知道在Heroku上进行部署还是在本地上进行部署时还需要设置其他因素。

我将典型的部署到Heroku步骤

$git init
$ heroku git:remote -a slamham
$ git add .
$ git commit -am "make it better"
$ git push heroku master  

日志不能很好地描述问题

2019-12-25T14:42:59.000000+00:00 app[api]: Build succeeded
2019-12-25T14:43:01.802807+00:00 heroku[web.1]: Starting process with command `npm start`
2019-12-25T14:43:04.649949+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-25T14:43:04.634670+00:00 heroku[web.1]: Process exited with status 0
2019-12-25T14:43:04.452419+00:00 app[web.1]: 
2019-12-25T14:43:04.452440+00:00 app[web.1]: > node-quickbooks@2.0.33 start /app
2019-12-25T14:43:04.452442+00:00 app[web.1]: > node
2019-12-25T14:43:04.452444+00:00 app[web.1]: 
2019-12-25T14:43:08.767084+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pingpong11.herokuapp.com request_id=f923d9de-b7c4-4cb4-a932-d22c42ef660e fwd="65.60.197.111" dyno= connect= service= status=503 bytes= protocol=http  

,应该加载应用程序的链接始终显示“应用程序错误 应用程序中发生错误,无法提供您的页面。如果您是应用程序所有者,请检查您的日志以了解详细信息。

同样,我要部署的应用的整个存储库为here

1 个答案:

答案 0 :(得分:1)

Heroku输出日志的第二行是

  

2019-12-25T14:43:01.802807 + 00:00 heroku [web.1]:使用命令node启动进程

package.json的开始脚本只有node oauth2example/app.js,而应该是"engines": { "node": "10.x" },

此外,您可能需要在package.json中的include the engines字段中。例如,

{{1}}
相关问题