【问题标题】:Meteor.js iron:router server route triggers RangeError: Maximum call stack size exceededMeteor.js iron:router server route triggers RangeError: Maximum call stack size exceeded
【发布时间】:2015-10-19 13:49:34
【问题描述】:

我正在我的服务器上设置 Stripe webhook 路由,并直接从 Iron 路由器的自述文件中复制了代码,但是当我将测试 webhook 从 stripe 发送到我的服务器时,我收到 RangeError。

我的路线定义如下:

Router.route('/webhooks/stripe', { where: 'server' })
.get(function () {
    // GET /webhooks/stripe
    console.log("Get request from stripe")
})
.post(function () {
    // POST /webhooks/stripe
    console.log("Received POST Webhook from Stripe");
    console.log(this);

    this.response.end('webhook ended');
})
.put(function () {
    // PUT /webhooks/stripe
    console.log("Put request from stripe")
})

我也尝试过这样定义路线:

Router.map(function(){
this.route("webhooks", {layoutTemplate:null, path:'/webhooks/stripe', where:"server"}).post(function () {
    // POST /webhooks/stripe
    console.log("Received POST Webhook from Stripe");
    console.log(this);
    // // NodeJS  response object
    // var response = this.response;

    this.response.end('webhook ended');
})
})

我正在使用 ultrahook 将测试 webhook 转发到我的本地开发机器。除了一次打印上述错误外,我没有得到任何控制台输出。 我还尝试使用 Chrome 扩展 Postman 访问端点,但收到相同的错误。

更新: 也尝试了这个路由定义没有改变

Router.route('/webhooks/stripe', function () {
    var req = this.request;
    var res = this.response;
    res.end('hello from the server\n');
}, {where: 'server'});

我必须做错事,但我无法找到适合我的示例。任何帮助表示赞赏。

【问题讨论】:

  • Maximum call stack size exceeded 几乎总是来自失控的递归调用。也请注意!
  • 是的,我知道这是正常原因,但在这种情况下,请求在引发该错误之前似乎甚至没有到达我的路线。感谢您的评论。

标签: javascript meteor stripe-payments iron-router webhooks


【解决方案1】:

好的,所以我在发布之前一直在看这个,结果发现我真的只需要更改我的 onBeforeAction 调用以排除服务器路由。

我有

Router.onBeforeAction(requireLogin, {except:["home"]});

我需要将其更改为

Router.onBeforeAction(requireLogin, {except:["home", "webhooks"]});

我的 requireLogin 方法如下所示:

var requireLogin = function() {

    if (! Meteor.user()) {
        if (Meteor.loggingIn()) {
            this.render(this.loadingTemplate);
        }else{
            Router.go('/');
            this.next();
        }
    } else {
        this.next();
    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多