アクセスを制限したいMeteorJsアプリケーションにダウンロードルートがあります。ルートコードは次のとおりです。Meteor JS(Iron Router) - サーバールートへのアクセスを制限する
Router.route("/download-data", function() {
var data = Meteor.users.find({ "profile.user_type": "employee" }).fetch();
var fields = [...fields];
var title = "Employee - Users";
var file = Excel.export(title, fields, data);
var headers = {
"Content-type": "application/vnd.openxmlformats",
"Content-Disposition": "attachment; filename=" + title + ".xlsx"
};
this.response.writeHead(200, headers);
this.response.end(file, "binary");
},
{ where: "server" }
);
ルートは自動的にファイルをダウンロードします。これは現在作業中ですが、私はルートへのアクセスを制限したいと思います。私は管理者がダウンロードできるようにしたい。
私は
Router.onBeforeAction(
function() {
//using alanning:roles
if(Roles.userIsInRole(this.userId, "admin"){
console.log('message') //testing
}
},
{
only: ["downloadData"]
}
);
以下のようにonBeforeAction
フックを作成し、onBeforeAcion
フックは何の効果
を負いません
//code above
this.response.writeHead(200, headers);
this.response.end(file, "binary");
},
{ where: "server", name: "downloadData" }
);
以下のようにまた、私はどちらもthis.userId
に気づいた私のルートの名前を変更したもMeteor.userId
は経路上で動作します