我收到一个Heroku H20错误(应用启动超时),然后是一个H10错误(Web进程无法在启动后60秒内绑定到$PORT )
我的starter svelte项目在package.json中使用了sirv:
{
"name": "clicker",
"version": "0.0.1",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public"
},
"engines": {
"node": "10.16.0",
"npm": "6.13.1"
},
"devDependencies": {
"rollup": "^1.12.0",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-terser": "^5.1.2",
"svelte": "^3.0.0"
},
"dependencies": {
"sirv-cli": "^0.4.4"
}
}
我似乎不知道如何传递Heroku提供的$PORT环境变量。我试过了
"start": "sirv public --port $PORT"
我发现的The closest solution指的是Heroku为你的应用动态分配一个端口的事实,但我发现的所有解决方案都指的是在节点中使用process.env.port,但我似乎想不出如何在我的package.json文件中将其与sirv一起使用。它基本上不是在命令行上运行'sirv public‘吗?所以我不能只在那里使用process.env.port,因为它用于访问代码中的端口变量……
Heroku日志
2019-12-02T07:54:26.210322+00:00 app[web.1]: Your application is ready~! �?
2019-12-02T07:54:26.210323+00:00 app[web.1]:
2019-12-02T07:54:26.210377+00:00 app[web.1]: - Local: http://localhost:19516
2019-12-02T07:54:26.210621+00:00 app[web.1]:
2019-12-02T07:54:26.210624+00:00 app[web.1]: LOGS
2019-12-02T07:54:26.210625+00:00 app[web.1]:
2019-12-02T07:55:08.914191+00:00 heroku[router]: at=error code=H20 desc="App boot timeout"
2019-12-02T07:55:24.799059+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-02T07:55:24.713988+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-12-02T07:55:24.714032+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-12-02T07:55:24.782218+00:00 heroku[web.1]: Process exited with status 137
2019-12-02T08:02:13.343213+00:00 heroku[router]: at=error code=H10 desc="App crashed"
有什么想法吗?
发布于 2020-03-07 04:27:03
创建一个包含以下内容的.env
文件(添加到.gitignore
):
HOST=localhost
PORT=5000
package.json
启动命令:
{
"start": "sirv public --host $HOST --port $PORT"
}
在本地运行进行开发时,执行:
heroku local
这将从.env
获取您的环境变量
在生产中,Heroku将提供$HOST
和$PORT
如果需要,可以用硬编码的0.0.0.0
替换$HOST
:
发布于 2019-12-02 08:22:39
By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the sirv commands in package.json to include the option --host 0.0.0.0.
我将它添加到我的package.json中,它成功地在heroku上完全上线了!
https://stackoverflow.com/questions/59134908
复制