如何使用 Meteor 创建动态文件

How to create a dynamic file with Meteor

我正在尝试让路由使用 Meteor 发回自定义生成的文件。一个例子是有一个路由,例如 https://example.com/image?text=hello+world 并让它发送一个带有呈现文本 "hello world" 的图像。

我该怎么做?有没有办法像使用 express 作为网络服务器时那样访问 req 和 res 变量?我基本上需要一个 res.send() 的流星。

谢谢

这是一个关于服务器端路由的问题。有多种选择。仍然最受欢迎的可能是 iron-router。使用它你可以写:

Router.route('/image', function () {
  const text = this.params.query.text;
  const image = callMagicFunctionToGenerateImageFrom(text);
  this.response.setHeader('Content-Type', 'image/png'););
  this.response.write(image);
}, {where: 'server'});

这里this.response是一个node.js HTTP Response object.