【问题标题】:Invalid Host error when deploying a create-react-app on Heroku在 Heroku 上部署 create-react-app 时出现无效的主机错误
【发布时间】:2018-12-25 10:33:02
【问题描述】:

当我在 Heroku 上部署我的 React 应用程序时,我收到了 Invalid Host 错误。

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

但是,当我创建 .env 文件并包含 HOST 时,我收到此错误:

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,但我仍然收到上述错误。

【问题讨论】:

    标签: reactjs heroku create-react-app


    【解决方案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/

    【讨论】:

      【解决方案2】:

      我曾经在 aws ec2 上部署时遇到同样的错误。然后我意识到问题在于我将端口包含在 HOST=xxxx.com 中。我一删除端口,它就在开发模式下工作。

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 2020-05-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-21
        • 2017-06-06
        • 2021-10-29
        • 2018-12-26
        • 2019-04-19
        相关资源
        最近更新 更多