简体   繁体   English

我尝试部署React Heroku应用时出现无效的主机头错误

[英]Invalid host header error as I try to deploy a react heroku app

I am trying to deploy a simple react application on heroku. 我正在尝试在heroku上部署一个简单的react应用程序。 As I deploy I see an error Invalid Host header . 在部署时,我看到一个错误的Invalid Host header I cannot understand the reason for this. 我不明白原因。 To prevent this error I created a .env.development file in the root and added: 为防止此错误,我在根目录中创建了一个.env.development文件并添加:

HOST=fce-bxxok-3517.herokuapp.com

but as I do this I still get an error saying Could not find an open port at fce-bxxok-3517.herokuapp.com/ . 但是在执行此操作时,我仍然收到错误消息,指出Could not find an open port at fce-bxxok-3517.herokuapp.com/

What could be the reason for this? 这可能是什么原因?

This is how my package.json looks like: 这是我的package.json样子:

    {
  "dependencies": {
    "antd": "latest",
    "bootstrap": "4.3.1",
    "react": "latest",
    "react-dom": "latest",
    "react-scripts": "1.0.0"
  },
  "name": "9n6m1",
  "description": null,
  "version": "0.0.303",
  "devDependencies": {
    "react-scripts": "1.0.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

I am fully not able to understand the issue but it looks like somewhere you are hard coding the value of the port which should not be done. 我完全无法理解该问题,但似乎您正在某个地方对端口的值进行硬编码,这是不应该做的。 Heroku automatically assigns a port to the app. Heroku自动为应用程序分配端口。

Also, if you want to just host the react js app on any server, you can use NETLIFY which will help you deploy your app in a lot easier way because it is actually built for it. 另外,如果您只想在任何服务器上托管react js应用程序,则可以使用NETLIFY ,因为它实际上是为应用程序构建的 ,它将帮助您以更简单的方式部署应用程序。 Heroku is mostly used for deploying server-side apps like Python, Flask, Ruby. Heroku主要用于部署服务器端应用程序,例如Python,Flask,Ruby。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM