[英]Listen for a webhook server side using meteor
I've set up a meteor app using iron-router
and I want the app to listen to a webhook from another service (basically I'm building an API for other services to use) 我已经使用
iron-router
设置了流星应用程序,并且希望该应用程序侦听来自其他服务的Webhook(基本上,我正在构建供其他服务使用的API)
So for example, when an external website calls myapp.meteor.com/webhook
I want to catch that specific link and parameters and do stuff with the data. 因此,例如,当外部网站调用
myapp.meteor.com/webhook
我想捕获该特定链接和参数,并对数据进行处理。
Update: Thanks to a comment I found this: https://github.com/iron-meteor/iron-router/blob/devel/Guide.md#server-routing 更新:感谢评论,我发现了这个: https : //github.com/iron-meteor/iron-router/blob/devel/Guide.md#server-routing
Router.route('/webhooks', { where: 'server' })
.post(function () {
console.log(this);
this.response.end('Caught you\n');
//this.response.status(200).json({text:"Todo added"});
});
I added the above in the /server
folder as there is no need to for the front-end server to worry about this like mentioned in the comment. 我将以上内容添加到
/server
文件夹中,因为前端服务器无需担心注释中提到的问题。 But when I load this using postman
POST request, it just returns my HTML for not found
. 但是,当我使用
postman
POST请求加载此文件时,它只会返回not found
HTML。 Any ideas? 有任何想法吗?
Thanks in advance for your help. 在此先感谢您的帮助。
UPDATE I tried what @David said and still I get the template loaded and nothing in the console. 更新我尝试了@David所说的内容,但仍然加载了模板,但控制台中没有任何内容。 Any idea what I'm doing wrong?
知道我在做什么错吗?
Your server route will only run if no client routes also match. 只有在没有客户端路由也匹配的情况下,您的服务器路由才会运行。 I suspect you have a catch-all route which is executing on the client and preventing the server route from running.
我怀疑您有一条在客户端上执行并阻止服务器路由运行的包罗万象的路由。 One solution is to define all of the routes in a common folder like
/lib
so that you can properly order them. 一种解决方案是在
/lib
类的公用文件夹中定义所有路由,以便您可以正确排序。 Your routes file could look something like: 您的路线文件可能类似于:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.