node.js - Node-express-Typescript:邮递员不断发送帖子请求
问题描述
我正在为我的应用程序使用节点打字稿。我使用邮递员提出了基本的发布请求。我控制台记录请求正文。我得到了数据,但在邮递员中不断显示发送请求和图像。我在我的代码中没有看到任何错误。我不知道发布请求中有什么问题。附言:This is my first time I am using node-typescript express server
。
这基本上是我所有的快递代码
import express, { Application, Response, Request } from 'express';
import cors from 'cors';
import morgan from 'morgan';
import helmet from 'helmet';
const app: Application = express();
const port = 8000;
app.use(cors());
app.use(morgan("common"));
app.use(helmet());
app.use(express.json());
app.post('/api', (req: Request, res: Response) => {
console.log(req.body.Item); // I get the data
})
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`)
})
这是我的命令脚本
"scripts": {
"build": "tsc -p .",
"start": "ts-node server.ts",
"server": "ts-node server.ts"
},
解决方案
您不会结束您的任何请求。一旦您的请求得到处理,您需要发送响应。
app.post('/api', (req: Request, res: Response) => {
console.log(req.body.Item); // I get the data
})
更新上面的块如下,
app.post('/api', (req: Request, res: Response) => {
console.log(req.body.Item); // I get the data
res.send()
})
如果你想发送任何响应,你可以将它传递给发送函数
推荐阅读
- javascript - li a:focus,当我在 iframe 中单击时防止焦点丢失
- firebase - 未处理的异常:类型“int”不是颤振中“字符串”类型的子类型
- reactjs - 反应 mapbox 图层,图标未出现
- swift - 获取请求后对CoreData实体进行排序的任何方式?
- eclipse - 如何将 pyDev 项目集成或嵌入到 Mule 或 Java 项目中
- machine-learning - 图神经网络中的转导与归纳
- python - Tesseract ocr 输出在检测到的文本之间带有单个字符
- arduino - 当点亮 8x8 矩阵中的特定 LED 时,整列不会关闭 Arduino Uno
- r - 3D散点图与R中的Plotly无线
- reactjs - React-Testing 库未在快照中呈现 Material-UI 对话框