在创build反应应用程序项目上进行快速身份validation

我正在开发一个带有Express后端的简单项目和一个使用create-react-app引导的前端:

 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调用都通过代理服务器成功redirect到端口3001。 在我的客户端package.json中:

 "proxy": "http://localhost:3001/", 

现在,一切工作正常,但我有困难的时间使login工作。 事实上,当他访问/login url时,我无法将用户redirect到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中的一个string)只能在非text / html请求中使用。

 Any unrecognized request without a text/html accept header will be redirected to the specified proxy. 

尝试手动执行: https : //github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#configuring-the-proxy-manually