如何解决带有 React 的 Digital Ocean 上的“无效主机头”Kubernetes 集群
在我对 React 应用程序进行最新更改之前,我的网站运行良好。当我部署更改时,网页上会出现“无效的主机标头”。
这是我的代码结构:
我可以配置什么来消除这个错误?
这是我的 package.json 文件:
{
"name": "client","proxy": "http://127.0.0.1:4000","version": "0.1.0","private": true,"dependencies": {
"@material-ui/core": "^4.11.2","@material-ui/icons": "^4.11.2","@material-ui/styles": "^4.11.2","@testing-library/jest-dom": "^5.11.6","@testing-library/react": "^11.2.2","@testing-library/user-event": "^12.6.0","axios": "^0.21.1","react": "^17.0.1","react-dom": "^17.0.1","react-router-dom": "^5.2.0","react-scripts": "4.0.1","web-vitals": "^0.2.4"
},"scripts": {
"start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
},"eslintConfig": {
"extends": [
"react-app","react-app/jest"
]
},"browserslist": {
"production": [
">0.2%","not dead","not op_mini all"
],"development": [
"last 1 chrome version","last 1 firefox version","last 1 safari version"
]
}
}
这是我的 pod 的日志:
> client@0.1.0 start
> react-scripts start
ℹ 「wds」: Project is running at http://10.244.1.23/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /app/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
Compiled successfully!
You can now view client in the browser.
Local: http://localhost:3000
On Your Network: http://10.244.1.23:3000
Note that the development build is not optimized.
To create a production build,use npm run build.
谢谢!
解决方法
所以我通过执行以下步骤解决了这个问题:
-
npm 在我的 react 应用程序文件夹中运行弹出。
-
转到配置文件夹的 webpackDevServer.config.js 文件并更改
disableHostCheck:!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
到
disableHostCheck: true,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。