node.js - 节点应用程序发布方法console.log中的bodyParser响应“未定义”
问题描述
我正在尝试使用中间件来捕获发布请求的主体,并动态使用 telnyx API 端点的消息 ID 来填充其他字段等。
多次遵循此处的文档,当我向我的 telnyx 号码发送消息时,无法让终端输出除未定义之外的任何内容:https ://developers.telnyx.com/docs/v2/messaging/quickstarts/receiving-短信和彩信
我尝试过 cors 认为这可能是我在其他帖子中读到的问题,并且知道 express 和 bodyParser 不再捆绑在一起,所以我也使用了所有这些来尝试捕获数据。如果很明显,请原谅我。
require('dotenv').config();
const axios = require('axios').default;
const cors = require('cors');
const telnyx = require("telnyx")("MYAPIKEY")
const express = require('express');
const app = express();
app.use(express.urlencoded( {extended: true} ));
app.use(express.json());
app.post('/webhook', (req, res) => {
console.log(`New message from ${req.body.from}: ${req.body.body}`);
});
const port = 8080;
app.listen(port, () => console.log(`App running on port ${port}`));
以下是依赖项:
{
"name": "telnyxjs",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.21.1",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"telnyx": "^1.13.1"
}
}
解决方案
推荐阅读
- authentication - 如何配置应用服务以使用来自 Terraform 的 Azure AD 登录
- apache-nifi - 如何在 Nifi 上读取 sql 表?
- vue.js - gridsome 在哪里添加路由器元数据
- angular - 指令未被调用
- c# - 正则表达式:在不同的字符串变体中查找字符串
- python - C++/嵌入式 Python:当从 Python 调用 C++ 函数时,我可以检索 Python 文件名和行号吗
- python - 这个 Numpy/Pandas 代码根据其他两个布尔列中的值构造新的布尔列有什么问题?
- javascript - 用两个函数初始化相同的数据表
- python-3.x - python requests.get() 不刷新页面
- node.js - 使用 tsyringe 使用 Typescript 进行动态依赖注入