異なるサブドメインを異なるプラグインにルーティングする方法を探しています。API docsを調べましたが、役立つものは何も見つかりませんでした。
1 に答える
1
最終的に、特定のサブドメインでのみ動作するプラグインを作成する単純なクラスを作成しました。ここにあります。
var Plugin = function(attributes, routes) {
// Add our routes to the server
this.register = function(plugin, options, next) {
// Loop through the selected servers and add the routes
plugin.servers.forEach(function(server) {
// Loop through the routes and add the vhost option
routes.map(function(route) {
route.vhost = attributes.vhosts.map(function(vhost) {
return vhost + "." + server.info.host;
});
});
// Add the routes
server.route(routes);
});
next();
};
// Add our attributes
this.register.attributes = attributes;
};
次に、新しいプラグインを作成して、サブドメインを簡単に指定できます。例:
var plugin = new Plugin([
// Your route or routes here
], {
vhosts: ["array", "of", "subdomains"]
});
于 2014-08-15T07:53:04.487 に答える