[英]Specifying content-type in Meteor (JavaScript)
How can I specify content-type in Meteor? 如何在Meteor中指定内容类型?
I've got a page that returns JSON but response header is html/text
I need to make it application/json
. 我有一个页面返回JSON但响应头是html/text
我需要使它成为application/json
。 I am using iron-router
and then the json is displayed through a template. 我正在使用iron-router
,然后通过模板显示json。 I just need to change the response header for that page. 我只需要更改该页面的响应头。
How can I do it? 我该怎么做?
Here's a simple example using a server-side route: 这是使用服务器端路由的简单示例:
Router.map(function() {
this.route('jsonExample', {
where: 'server',
path: '/json',
action: function() {
var obj = {cat: 'meow', dog: 'woof'};
var headers = {'Content-type': 'application/json'};
this.response.writeHead(200, headers);
this.response.end(JSON.stringify(obj));
}
});
});
If you add that to your app and go to localhost:3000/json
you should see the correct result. 如果您将其添加到您的应用程序并转到localhost:3000/json
您应该看到正确的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.