見2例下發送MeteorChef網站的響應部分,
Router.route("users/:name/profile", function() {
var name = this.params.name,
query = this.request.query,
fields = {};
fields[ query.field ] = query.field;
var getUser = Meteor.users.findOne({ "profile.username": name }, { fields: fields });
if (getUser) {
this.response.statusCode = 200;
this.response.end(getUser.profile);
} else {
this.response.statusCode = 404;
this.response.end({ status: "404", message: "User not found." });
}
}, { where: "server" });
所以你可以使用this.response.end
像這樣把你的數據,
Router.route("/api/test", function() {
this.response.writeHead(200, {
'Access-Control-Allow-Origin': '*'
});
this.response.statusCode = 200;
//this.response.data = {test: 'test'};
this.response.end({ test: 'test' });
}, {where: 'server'});
我從來沒有嘗試過服務器端路由自己,所以我不確定它是否有效。