在Heroku上部署create-react-app时出现无效的主机错误

时间:2018-07-17 16:23:56

标签: reactjs heroku create-react-app

当我在Heroku上部署React应用时,我收到一个无效的主机错误。

搜索原因时,我在文档中找到了这个原因:https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#invalid-host-header-errors-after-configuring-proxy

但是,当我创建一个.env文件并包含主机时,会出现此错误:

Attempting to bind to HOST environment variable: XXX.herokuapp.com
If this was unintentional, check that you haven't mistakenly set it in your shell.

Could not find an open port at XXX.herokuapp.com.
Network error message: listen EADDRNOTAVAIL 52.205.227.252

我在做什么错了?

更新:我已经通过.env文件和Heroku CLI将HOST变量设置为Heroku url,但是仍然出现上述错误。

2 个答案:

答案 0 :(得分:1)

这是一个有点古老的问题,但是在处理同一问题时遇到了许多问题之一,因此,我在分享我所学到的知识,并希望它对其他人有用。

一个可行的解决方案是使用http-proxy-middleware手动设置代理。请在此处查看说明:deploying create-react-app to heroku with express backend returns invalid host header in browser

这是一个最小的工作示例:https://github.com/sehailey/proxytest 这是部署的示例:https://proxytest2.herokuapp.com/

答案 1 :(得分:0)

在aws ec2上进行部署时,我经常遇到相同的错误。然后,我意识到问题出在我将端口包含在HOST = xxxx.com中。当我删除端口后,它便以开发人员模式工作。

希望这会有所帮助

相关问题