Skip to content

Instantly share code, notes, and snippets.

@dpaez
Last active April 22, 2016 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpaez/11650576fc0fe1ae1c9b8d3f8e578272 to your computer and use it in GitHub Desktop.
Save dpaez/11650576fc0fe1ae1c9b8d3f8e578272 to your computer and use it in GitHub Desktop.
hapijs, plugins options via route issue.
// There is a route, like this
var route = {
  method: 'GET',
  path: '/{agencyDomain}',
  handler: handler.home,
  config: {
    pre: [ {
      method: somePreMethod,
      assign: 'somePreMethod'
    }],
    plugins: {
      https_checker: { enabled: true }
    }
  }
}

// server.js

server.register(plugins, function(err){
  //if err do something
  ...
  server.route( route )
  ...
}) 

// and the plugin looks something like this

var httpsCheckerHandler = function(server, options, next) {

  server.ext('onRequest', function(request, reply) {

      // request.route.settings.plugins is an empty object :(
       LOGGER.error(`###################--x->:[${JSON.stringify(request.route.settings.plugins)} - ${request.path}]`);

       if (options.enabled) {
           handler.start(request, reply, LOGGER);
       } else {
           reply.continue();
       }

  });
  next();
};


httpsCheckerHandler.attributes = {
  name: 'https_checker',
  version: '1.0.0'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment