无法在 Heroku 上部署后端

时间:2021-03-04 11:54:53

标签: node.js git heroku deployment backend

我是后端方面的新手。我需要部署一个完整的堆栈应用程序。我会将前端部署到 Netlify,后端部署到 Heroku。

我已经设法通过终端在 Heroku 上部署了后端(node.js)。但是,它不会响应 fetch 的任何请求。

这就是我目前在后端文件夹中所做的。

heroku create
git add .
git commit -am "Some commit"
git push heroku

所以它奏效了,我在 Heroku 中看到了我的后端应用程序。但是,当我打开应用程序时,我看到的只有 Heroku 的默认“欢迎使用您的应用程序”页面。

我尝试通过 Heroku 链接获取数据,但得到的只是 502 错误。我已经在 Postman 上进行了测试,响应只是默认 Heroku 欢迎页面的标记。

我尝试获取时终端中的错误日志如下。

2021-03-04T11:41:52.037366+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/search?q=matrix%204" host=salty-meadow-59254.herokuapp.com request_id=3b671893-c701-4319-a93a-8725063a5fd3 fwd="176.33.88.191" dyno= connect= service= status=502 bytes= protocol=https

在此先感谢您的帮助

1 个答案:

答案 0 :(得分:1)

在部署任何代码之前,Heroku 会向访问者显示一条通用的欢迎信息。此页面带有 HTTP 状态代码 502,表示应用尚未运行。

https://devcenter.heroku.com/articles/creating-apps

Heroku 只部署你推送到 master 或主分支的代码。

git push heroku master

https://devcenter.heroku.com/articles/git#deploying-code