create"/>
在create
我正在使用Express后端和用create-react-app
引导的Frontfront进行一个简单的项目:
my-project
|- server.js # backend entry point
|- client/
|-- package.json # client package.json
|-- index.js # client entry point
遵循一些指南( 像这样 ),我现在在localhost:3001
上有一个可用的后端服务,在localhost:3000
上有一个可用的前端服务。
使用代理服务器/api/myapi
所有api调用成功重定向到端口3001。 在我的客户端package.json中:
"proxy": "http://localhost:3001/",
现在,一切正常,但我很难使登录正常工作。 实际上,当用户访问/login
网址时,我无法将其重定向到登录页面。 在我的server.js
文件中:
app.get('/login', function(req, res) {
res.send('This is the login page');
});
这根本行不通,URL /login
却给了我一个空白页(看起来根本不在端口3001上)。
既然这是我第一次使用Express,那么有人可以这么向我解释为什么这行不通吗?
回答如下:根据create-react-app中的文档,代理(作为package.json中的字符串)仅适用于非text / html请求。
Any unrecognized request without a text/html accept header will be redirected to the specified proxy.
尝试手动执行: https : //github/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#configuring-the-proxy-manually
更多推荐
在create
发布评论