我正在尝试在heroku上部署一个简单的React应用程序。当我部署时,我看到错误无效的主机 header
。我无法理解其中的原因。为了防止出现此错误,我在根目录中创建了一个 .env.development
文件并添加了:
HOST=fce-bxxok-3517.herokuapp.com
但当我这样做时,我仍然收到错误消息:Could not find an open port at fce-bxxok-3517.herokuapp.com/
。
这可能是什么原因?
这就是我的 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"
}
}
最佳答案
我完全无法理解这个问题,但看起来你在某个地方对端口的值进行了硬编码,这是不应该做的。 Heroku 会自动为应用程序分配端口。
此外,如果您只想在任何服务器上托管 React js 应用程序,您可以使用NETLIFY,它将帮助您以更轻松的方式部署您的应用程序,因为它实际上是为此构建的。 Heroku 主要用于部署服务器端应用程序,例如 Python、Flask、Ruby。
关于javascript - 当我尝试部署 React heroku 应用程序时出现无效的主机 header 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57443279/