如何使用 Iron Router 在 Meteor 中生成 XML 文件

How to generate XML files in Meteor using Iron Router

我需要生成一个简单的 XML 文件来调用 Twilio

目前,我正在尝试在特定路线上输出:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say voice="woman" language="en">Hello, world!</Say>
</Response>

我计划稍后将其动态化,因此无法将其与其他资产文件放在一起。

在我的路线文件中,我不确定该怎么做。我不能将它放在模板中,因为显而易见的原因会导致错误。

// Twilio voice call TwiML
Router.route('/twilio/my_twiml.xml', {
    // ??
});

this 回答的帮助下,我能够通过以下方式实现它:

Router.route('/twilio/my_twiml.xml', {
  where: 'server',
  action: function() {

    var xmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    xmlData += "<Response>";
    xmlData += "<Say voice=\"woman\" language=\"en\">Hello!</Say>";
    xmlData += "</Response>";

    this.response.writeHead(200, {'Content-Type': 'application/xml'});
    this.response.end(xmlData);
  }
});

请注意,这是服务器端路由。