将节点模块与Meteor一起使用

时间:2012-11-08 21:12:53

标签: node.js meteor postmark

我有一个非常简单的流星应用程序。 我想在这个应用程序中使用邮戳api幸运的是我们有一个node.js模块 https://github.com/voodootikigod/postmark.js
我已成功将此模块安装到节点,可以看到它就在那里 我所涉及的每一种资源都告诉我,现在可以通过Meteor以简单的要求访问它 到目前为止,这是我的代码


    if (Meteor.isClient) {
      Template.hello.greeting = function () {
        return "Welcome to postmarkapp.";
      };

      Template.hello.events({
        'click input' : function () {
          // template data, if any, is available in 'this'
          if (typeof console !== 'undefined')
            Meteor.call('sendMail',function(error,result){
              console.log(result);
            });
          }
      });
    }

    if (Meteor.isServer) {
    var require = __meteor_bootstrap__.require;
    postmark = require("postmark")('API_KEY');
        Meteor.methods({
          sendMail: function() {

            return postmark;

          }
        });

    }

现在我运行此方法时没有出现任何错误,但是我确实得到了一个没有方法的空对象。看一下邮戳模块,我应该用一个方法“send”来获得一个对象。

任何人都可以告诉我可能出错的地方吗?我认为它可能在节点模块的包含中以及在Meteor应用程序中使用该模块。

我已经广泛查看了Meteor的文档,似乎无法找到与此主题相关的任何内容。

提前谢谢。

1 个答案:

答案 0 :(得分:1)

此代码尝试将postmark.send函数返回给客户端。这是不可能的。方法只能返回JSON可序列化值。

您应该能够在方法体内使用邮戳的send功能,但根据其界面,您可能需要将其包裹在光纤中。

相关问题