node.js - 我的 NodeJS 服务器在 6 个 Axios 发布请求后崩溃
问题描述
我在 ReactJS 中创建了一个前端,在 NodeJS 中创建了一个后端的应用程序。我正在做的是让前端每次在输入中输入一个字母时与后端进行通信。它工作正常(我可以在我的 NodeJS 控制台中看到我输入的每个字母),但是在此输入中敲击键盘 6 次后,我的 NodeJS 服务器崩溃,并且似乎没有响应(我没有错误)。
我试图搜索它是否不是 Axios 的问题,因为我认为一旦完成后查询它就不会断开连接,但我没有找到任何关于此的信息。
我准确地说我是 React 和 Node 的新手,所以我可能会跳过一些内容。
在 App.js 中
//This is the React Part
handleAttachmentToTask = async (event) =>{
let self = this;
const target = event.target;
const keystone = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
const postman = {kSent: keystone};
axios.post('/api/sandbox',{postman})
.then(response => {
//self.setState({keystone:response.data});
console.log(response.data);
})
.catch(error => {
console.log(error);
});
}
在 server.js 中
//This is the NodeJS part
app.post('/api/sandbox', function(req, res){
var hit = req.body.postman.kSent;
console.log(hit);
});
我只是想在我的 NodeJS 控制台上看到键盘敲击,但目前,正如我提到的,它在 6 个字母后崩溃。
感谢帮助
解决方案
您的服务器没有将响应发送回客户端。尝试发送响应。尝试更改您的服务器代码。
app.post('/api/sandbox', function(req, res){
var hit = req.body.postman.kSent;
console.log(hit);
res.send(200); // Try to send response back to user
});
推荐阅读
- php - 从本地主机替换 WordPress 主题而不会丢失生产站点数据
- postfix-mta - Modoboa 安装中的 Postfix 收件人地址被拒绝:无法投递 地址:mail for example.com 循环返回
- powerbi - 是否可以在 power bi 嵌入式中对视觉数据进行排序?
- odoo - 库存报告 odoo12 中的某些批次/序列号未显示现有数量
- r - [google-colaboratory]如何使用 R 内核在 google-colaboratory 上设置 X11 DISPLAY 变量
- html - 如何用css做空心
- c++ - 为什么不允许将 const char * 分配给 const 变量?
- php - 为什么 Laravel 中的验证不能正常工作?
- sql - Codility PostgreSQL 问题:SQL 查询中的聚合和条件。完全卡住
- vue.js - 如何为 ex 之类的按钮组件创建自己的可重用属性。vuetify 的 fab,dark,small,color="primary",而不在 vue .js 中使用 vuetity