hapijs - Multiple connections on a hapi server -


i want add plugins hapi server has multiple connections listening on different ips.

is possible add plugin servers configured?

or how loop on servers add plugin of them?

by default plugins add routes connections when calling server.route().

to limit connections plugin adds routes to, can use labels when creating connections , specify labels when registering plugins. here's example:

var hapi = require('hapi');  var server = new hapi.server();  server.connection({ port: 8080, labels: 'a' }); server.connection({ port: 8081, labels: 'b' }); server.connection({ port: 8082, labels: 'c' });  var plugin1 = function (server, options, next) {      server.route({         method: 'get',         path: '/plugin1',         handler: function (request, reply) {              reply('hi plugin 1');         }     });      next(); }; plugin1.attributes = { name: 'plugin1' };  var plugin2 = function (server, options, next) {      server.route({         method: 'get',         path: '/plugin2',         handler: function (request, reply) {              reply('hi plugin 2');         }     });      next(); }; plugin2.attributes = { name: 'plugin2' };  server.register(plugin1, function (err) {      if (err) {         throw err;     }      server.register(plugin2, { select : ['a'] }, function (err) {          if (err) {             throw err;         }          server.start(function () {              console.log('server started');         })     }); }); 

get /plugin1 route plugin1 responds on :

http://localhost:8080/plugin1 http://localhost:8081/plugin1 http://localhost:8081/plugin2 

where get /plugin2 route plugin2 responds on:

http://localhost:8080/plugin2 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -