Meteor.js iron:路由器服务器路由触发RangeError:最大调用堆栈大小超出

Meteor.js iron:router server route triggers RangeError: Maximum call stack size exceeded

本文关键字:调用 堆栈 RangeError iron js 路由器 服务器 路由 Meteor      更新时间:2023-09-26

我正在我的服务器上设置一个Stripe webhook路由,并直接从readme中复制了铁路由器的代码,但是当我从Stripe发送测试webhook到我的服务器时,我得到了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扩展邮差到达端点,我收到同样的错误。

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

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

我必须做错了什么,但我没能找到一个例子,确实为我工作。

好的,所以我花了永远看这个之前,我张贴了这个,事实证明,我真的只需要改变我的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();
    }
};