meteor - Meteor - 创建一个 webhook
问题描述
我想用 Meteor 实现一个 webhook
我正在使用kadira/flowrouter Meteor 插件,但无法获取 POST 数据。queryParams 或 params 都不返回我想要获取的消息的正文。
FlowRouter.route('/my_weebhook', {
action: function(params, queryParams) {
console.log(queryParams);
console.log(params);
}
});
解决方案
我不知道如何使用 kadira/flowrouter 但你可以使用 Meteor 基础包WebApp
达到你所需要的。下面是一个示例代码。您需要在 server.js 中编码或导入类似的内容
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import url from "url";
WebApp.connectHandlers.use('/my_webhook', (req, res) => {
//Below two lines show how you can parse the query string from url if you need to
const urlParts = url.parse(req.url, true);
const someVar = urlParts.query.someVar;
//Below code shows how to get the request body if you need
let body = "";
req.on('data', Meteor.bindEnvironment(function (data) {
body += data;
}));
req.on('end', Meteor.bindEnvironment(function () {
//You can access complete request body data in the variable body here.
console.log("body : ", body);
//write code to save body in db or do whatever you want to do with body.
}));
//Below you send response from your webhook listener
res.writeHead(200);
res.end("OK");
});
推荐阅读
- java - 字符串数组 String [] 非 null 导致 ResultSet 中的 null 抛出 NullPointerException
- python - 使用代理连接 Python 库
- list - 将文本(表单)字段输入添加到列表
- google-chrome - 暂停 chrome.webRequest.onBeforeRequest 直到消息 | Chrome 扩展程序
- java - 列表升序和降序排序的规则是怎样的?
- r - 在 R 中使用 ggplot2 控制两个变量的双 geom_ribbon 的颜色
- c++ - C++17如何测试类有成员变量?
- java - 试图编写一个 Junit 测试,但它失败了
- three.js - 修改 Three.js 中的顶点后如何导出网格?
- html - CSS 图像尺寸不正确