git Heroku 无法获取 /
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24566635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Heroku Cannot GET /
提问by bullcitydave
I am new to Heroku and believe I am following all of the steps outlined on Heroku's website to deploy via node.js – https://devcenter.heroku.com/articles/getting-started-with-nodejs– but despite indications of success, I only see this in the browser when I go to my newly-generated herokuapp.com site.
我是 Heroku 的新手,相信我正在按照 Heroku 网站上概述的所有步骤通过 node.js 进行部署 – https://devcenter.heroku.com/articles/getting-started-with-nodejs– 但尽管有成功的迹象,当我访问我新生成的 herokuapp.com 站点时,我只会在浏览器中看到这个。
Cannot GET /
不能获取 /
No errors when executing
执行时没有错误
git push heroku master
My Procfile is simply
我的 Procfile 很简单
web: node app.js
I dont quite understand dynos yet, but there seems to be one running:
我还不太了解 dynos,但似乎有一个正在运行:
heroku ps === web (1X):
node app.js
web.1: up 2014/07/03 23:55:00 (~ 18m ago)
heroku ps === web (1X):
node app.js
web.1: up 2014/07/03 23:55:00 (~ 18m ago)
Then:
然后:
heroku open Opening APP-NAME... done
heroku open Opening APP-NAME... done
But https://APP-NAME.herokuapp.com/just displays the Cannot GET /message.
但https://APP-NAME.herokuapp.com/只显示无法获取 /消息。
回答by bullcitydave
I had my distdirectory included in my .gitignorefile so I was not committing dist to my repo and not pushing it to Heroku. Therefore, Heroku could not find any content to serve.
我的.gitignore文件中包含了我的dist目录,所以我没有将 dist 提交到我的仓库,也没有将它推送到 Heroku。因此,Heroku 找不到任何要提供的内容。
I updated my .gitignore, committed, and pushed, and my app shows up just fine on Heroku now.
我更新了我的 .gitignore、提交和推送,我的应用程序现在在 Heroku 上显示得很好。
回答by diegolameira
almost 3 years, but I'm answering for reference.
快3年了,但我正在回答以供参考。
- generally /dist is a build process generated directory, it's temporary and changes a lot while working in our sources, so /dist is not versioned.
- on your package.json you can add a script called postinstall with this build process, let's say you have a task in gulp called build...so "postinstall": "gulp build"
- if you manage your project's dependencies in bower too, npm install --save bower and "postinstall": "./node_modules/bower/bin/bower install && gulp build"
- 通常 /dist 是构建过程生成的目录,它是临时的,在我们的源代码中工作时会发生很多变化,因此/dist 不是版本化的。
- 在你的 package.json 上,你可以在这个构建过程中添加一个名为 postinstall 的脚本,假设你在 gulp 中有一个名为 build 的任务......所以“postinstall”:“gulp build”
- 如果您也在 bower 中管理项目的依赖项, npm install --save bower 和 "postinstall": "./node_modules/bower/bin/bower install && gulp build"
Just a simple example croped for your package.json
只是为您的 package.json 裁剪的一个简单示例
{
"dependencies: {
"bower":"^1.8.0",
"grunt":"^1.0.1",
},
"scripts": {
"start": "node ./www.js",
"build": "grunt dist",
"postinstall": "./node_modules/bower/bin/bower install && npm run build"
}
}
Obvious you're probably done and better nowadays...I'm just referencing it for next consultings.
很明显,您现在可能已经完成并且更好了……我只是在下次咨询时参考它。
回答by user9784639
I would think you haven't added the files to git. Whatever file you've edited on your local machine, you need to git add xyz.ext
, git commit -m "Message"
, git push heroku master -u
(-u
will save the 'heroku master' parameters so future additions you will only need to type git push
).
In short, every time you're asked to deploy the app, you need to git add
, git commit
, git push
. Hope that helps.
我认为您还没有将文件添加到 git 中。无论您在本地机器上编辑过什么文件,您都需要git add xyz.ext
, git commit -m "Message"
, git push heroku master -u
(-u
将保存 'heroku master' 参数,以便将来添加您只需键入git push
)。简而言之,每次要求您部署应用程序时,您都需要git add
, git commit
, git push
。希望有帮助。
回答by Roberto Rodriguez
Make sure you have these 2 things in place:
确保您已准备好以下 2 件事:
In your package.json, include heroku-postbuild line, in my case is like this, (it might change if you need to do more than one install)
"scripts": { "heroku-postbuild": "npm install --prefix client && npm run build --prefix client"
},
In your index.js file, add a condition for production
if (process.env.NODE_ENV === "production") {
app.use(express.static("build")); app.get("*", (req, res) => { res.sendFile(path.resolve(__dirname, "build", "index.html")); }); }
Express will serve up production assets like our main.js file, or main.css file!
Finally- Express look if the request is for an asset Express will serve up the index.html file if it doesn't recognize the route
在你的 package.json 中,包括 heroku-postbuild 行,在我的情况下是这样的,(如果你需要做不止一个安装,它可能会改变)
"scripts": { "heroku-postbuild": "npm install --prefix client && npm run build --prefix client"
},
在您的 index.js 文件中,添加生产条件
如果(process.env.NODE_ENV ===“生产”){
app.use(express.static("build")); app.get("*", (req, res) => { res.sendFile(path.resolve(__dirname, "build", "index.html")); }); }
Express 将提供生产资产,例如我们的 main.js 文件或 main.css 文件!
最后 - Express 查看请求是否是针对资产的 Express 将提供 index.html 文件,如果它无法识别路由
回答by Omar
I dont know why it worked but i changed the location of my angular /dist
from [root]client/dist
to [root]/dist
which is at the same directory level as server.js
我不知道它为什么会起作用,但我将 angular 的位置/dist
从[root]client/dist
更改[root]/dist
为 与在同一目录级别server.js
回答by QauseenMZ
回答by JanBrus
I'm a little bit embarrased but my error was running git push heroku master without the changes being commited.
我有点尴尬,但我的错误是在没有提交更改的情况下运行 git push heroku master。