【发布时间】:2020-08-12 03:15:06
【问题描述】:
我有几个关于 ReactJS 在开发和生产中应该如何工作的问题。我的 ReactJS 应用程序是从 creare-react-app 样板开始构建的。我有一个 SpringBoot 后端监听端口 8080。我注意到的第一件事是,如果我设置这样的代码来发出请求,代码会挂起:
async componentDidMount() {
...
const response = await fetch('http://localhost:8080/api/compliance');
我需要把它转换成:
async componentDidMount() {
...
const response = await fetch('/api/compliance');
然后添加一行:
"proxy": "http://localhost:8080",
这很好用。问题是当我把它放在一个预生产环境(或集成环境)中时,我有一个像http://www.mywebsite.com 这样的 URL,我得到了:
Invalid Host Header
在网上看,我注意到这可能是:
1. proxy that checks. the HTTP Header host and verify it to avoid security attacks
2. webpack package
我想了解:
1. Is proxy really necessary to let ReactJS app talk with its backend?
2. If no, how I can solve the issue (currently solution on the web didn't solve my problem)?
【问题讨论】:
标签: reactjs