bul*_*ave 12 git deployment heroku gitignore node.js
我是Heroku的新手,并且相信我遵循Heroku网站上列出的所有步骤,通过node.js进行部署 - https://devcenter.heroku.com/articles/getting-started-with-nodejs - 尽管有成功的迹象,当我去新生成的herokuapp.com网站时,我只在浏览器中看到这个.
不能获取 /
执行时没有错误
git push heroku master
Run Code Online (Sandbox Code Playgroud)
我的Procfile很简单
web: node app.js
Run Code Online (Sandbox Code Playgroud)
我还不太了解dynos,但似乎有一个正在运行:
heroku ps === web(1X):
node app.jsweb.1:up 2014/07/03 23:55:00(~18m ago)
然后:
heroku打开打开APP-NAME ...完成
但https://APP-NAME.herokuapp.com/只显示无法获取/消息.
bul*_*ave 28
我把我的dist目录包含在我的.gitignore文件中,所以我没有对我的repo进行dist而不是将它推送到Heroku.因此,Heroku无法找到任何内容.
我更新了我的.gitignore,承诺和推送,现在我的应用程序在Heroku上显示正常.
小智 7
差不多3年了,但我回答是为了参考.
只是一个简单的例子,你的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"
}
}
Run Code Online (Sandbox Code Playgroud)
显而易见,你现在可能已经做得更好了......我只是将它引用到下一个咨询中.
确保您已准备好以下 2 件事:
"scripts": {
"heroku-postbuild": "npm install --prefix client && npm run build --prefix client"
},
Run Code Online (Sandbox Code Playgroud)
if (process.env.NODE_ENV === "production"{
app.use(express.static("build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "build", "index.html"));
});
}
Run Code Online (Sandbox Code Playgroud)
Express 将提供生产资产,例如我们的 main.js 文件或 main.css 文件
最后 - Express 查看请求是否是针对资产的,如果 Express 无法识别路由,它将提供 index.html 文件
| 归档时间: |
|
| 查看次数: |
12522 次 |
| 最近记录: |