簡體   English   中英

Meteor.js iron:路由器服務器路由觸發器RangeError:超出最大調用堆棧大小

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

我正在服務器上設置Stripe Webhook路由,並已直接從Iron Router的自述文件中復制了代碼,但是當我將測試Webhooks從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將測試webhooks轉發到我的本地開發計算機。 除了一次打印以上錯誤外,我沒有任何控制台輸出。 我也嘗試使用Chrome擴展程序Postman擊中端點,並且收到相同的錯誤。

更新:還嘗試了此路由定義,沒有任何更改

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();
    }
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM