ruby-on-rails - 运行 'react-script start' 得到 400 错误请求
问题描述
我正在开发一个简单的 RoR 后端、React 前端应用程序,并且我有一些 API 请求来从数据库中获取数据。目前,我正在使用 axios 发出如下请求:
axios.get('/api/session/user')
问题是当我bundle exec rails server
在终端上运行服务器时,它会发出正确的请求并获取数据。但是,当我运行npm start
“react-script start”时,我总是在我提出请求的任何 api 上收到 400 Bad Request。
我使用 Postman 进行了测试,以获取或发布数据都在运行rails server
,npm start
但只有在使用npm start
. 我需要做什么才能使其在react-script start
( npm start
) 中运行?
在 package.json 中,我将代理设置为"proxy": "http://localhost:3000/"
. 但是,当我将端口更改为 3001 时,我得到 500 Internal Server Error 而不是 400 Bad Request。当我运行时,端口 3000 和 3001 都可以正常工作rails server
。
解决方案
推荐阅读
- javascript - 如何使用 Node 在 IBM 云函数中保存 API 用户身份验证令牌?
- wordpress - Wordpress,403错误无法通过常规方法解决
- javascript - 在 1 个单元格中合并为值(文本和日期时间格式为 yyyy-mm-dd hh:mm)
- google-apps-script - 使用 Google 脚本创建图表时,如何为 Google 表格图表设置图表 ID?
- angular - 如何仅在单个浏览器选项卡中与 Angular 中的组件共享数据?
- r - 基于字符串前缀的data.frame行逻辑子集
- json - 通过 JSON Rest 服务传输正则表达式验证模式
- postgresql - User 和 Contact 模型之间的关联是否正确?
- scala - Spark DataFrame 联合递归
- javascript - 谷歌标签管理器和使用触发器或标签排序