在create

编程入门 行业动态 更新时间:2024-10-07 14:30:02

在<a href=https://www.elefans.com/category/jswz/34/1771424.html style=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

本文发布于:2024-05-06 19:54:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753768.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:create

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!