【问题标题】:What is the equivalent of Express res.send() in Meteor?Meteor 中的 Express res.send() 等价物是什么?
【发布时间】:2015-11-17 19:26:46
【问题描述】:

我正在尝试将 Express 中的 res.send() 用于 Meteor 项目,而不使用像 glallowshark:meteor-express 这样的 Meteor 包:https://github.com/glittershark/meteor-express

我想知道是否存在仅使用 Meteor 而不是在 Meteor 之上添加 Express 的解决方案?特别是,如何在 Meteor 中使用 res.send()http://expressjs.com/4x/api.html#res.send

这是来自https://github.com/twitterdev/cannonball-web/blob/master/routes/index.js的NodeJS代码sn-p

var express = require('express');
var router = express.Router();
var request = require('request');

request.get(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
  // Send the verified phone number and Digits user ID.
  var digits = JSON.parse(body)
  return res.send({
    phoneNumber: digits.phone_number,
    userID: digits.id_str,
    error: ''
  });
}

一年前发布的一个很好的答案建议使用纤维。自从这篇文章以来,Meteor 发生了很多变化,我想避免使用纤维: Is there an easy way to convert an express app to meteor?

我将此链接添加到另一个可能有助于回答我的问题的相关答案:Porting Express App to Meteor

感谢阅读。 :)

【问题讨论】:

  • 您是要将此数据发送到流星客户端,还是作为任何客户端的休息服务?
  • 感谢您的回复。我正在为 Twitter Fabric Digit 开发 Meteor 帐户登录包:github.com/christieewen/accounts-fabric-digits 它还没有准备好发布,但它现在可以使用包 glallowshark:meteor-express 我的想法是,启用 Express 似乎有点过分流星的顶部,但如果这是正确的方法,我不反对。这是我第一次写 Meteor 包。

标签: node.js express meteor twitter-digits


【解决方案1】:

many good, simple ways you can add a rest api that serves json to a meteor app(我推荐restivus),但是你强加给自己的要求只会让你很难。
WebApp.connectHandlers and connect是你可以使用的低级api,但是您只是想避免使用 Fibers,这只是在要求更多的困难,因为这就是 Meteor 中的工作方式。

与其试图将方形钉钉入圆孔,我建议您选择以下两个选项之一:

【讨论】:

猜你喜欢
  • 2016-11-08
  • 2014-05-08
  • 2014-06-12
  • 1970-01-01
  • 2022-11-28
  • 2021-06-19
  • 2012-07-20
  • 2023-03-30
  • 2011-04-08
相关资源
最近更新 更多