Skip to content
/ glue Public
forked from hapijs/glue

Server composer for hapi.js

License

Notifications You must be signed in to change notification settings

Selvatico/glue

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#glue

Server composer for hapi.js.

Build Status

Lead Maintainer - Chris Rempel

Interface

Glue exports a single function compose accepting a JSON manifest file specifying the Hapi server options, connections and plugins. Glue primarily works in synergy with Rejoice, but can be integrated directly into any Hapi application loader.

  • compose(manifest, [options], callback)
    • manifest - an object having:
      • 'server' - an object containing the options passed to new Server([options])
      • 'connections' - an array of connection options, passed individually in calls to server.connection([options])
      • 'plugins' - an object or array of objects holding plugin entries to register with server.register(plugins, [options], callback). Note that when using an object, the order of registration is not guaranteed, while with the array it is. Still when you want absolutely guarantee the order of plugin loading use the hapi built in way, server.dependency(dependencies, [after]). Each key is the name of the plugin to load and register and the value is one of:
        • an object to use as the plugin options which get passed to the plugin's registration function when called.
        • an array of objects where each object will load a separate instance of the plugin. Multiple instances of a plugin is only possible if the plugin's attributes.multiple is true. Each object can have:
          • any option from server.register options
          • options - an object to use as the plugin options which get passed to the plugin's registration function when called.
    • options - an object having
      • 'relativeTo' - a file-system path string that is used to resolve loading modules with require. Used in server.cache and plugins[name]
      • 'preConnections' - a callback function that is called prior to adding connections to the server. The function signature is function (server, next) where:
        • server - is the server object returned from new Server(options).
        • next- the callback function the method must call to return control over to glue
      • 'prePlugins' - a callback function that is called prior to registering plugins with the server. The function signature is function (server, next) where:
        • server - is the server object with all connections selected.
        • next- the callback function the method must call to return control over to glue
    • callback - the callback function with signature function (err, server) where:
      • err - the error response if a failure occurred, otherwise null.
      • server - the server object. Call server.start() to actually start the server.

Usage

You create a manifest and then you can use the manifest for creating the new server:

var Glue = require('glue');

var manifest = {
  server: {
    debug: {
      request: ['error']
    }
  },
  connections: [{
    port: 8080
  }],
  plugins: {
    './routes/index': {}
  }
};

var options = {
  relativeTo: __dirname
};

Glue.compose(manifest, options, function (err, server) {

    if (err) {
        throw err;
    }
    server.start(function () {

        console.log('woot');
    });
});

About

Server composer for hapi.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%