Package Exports
- moonboots_hapi
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (moonboots_hapi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
moonboots_hapi
Moonboots plugin that allows it to serve files using a hapi server. Be sure to use hapi 2.x (won't work on 1.x, see legacy branch for 1.x)
How to use:
Exactly like you would expect, except it's a plugin now (which means it registers the catchall route itself). Also you don't pass in a server parameter.
var Hapi = require('hapi');
var moonboots_config = {
main: __dirname + '/sample/app/app.js',
developmentMode: false,
libraries: [
__dirname + '/sample/libraries/jquery.js'
],
stylesheets: [
__dirname + '/styles.css'
]
};
var server = new Hapi.Server();
server.pack.require({moonboots_hapi: moonboots_config}, function (er) {
server.start();
});Additional options
If your app has something like auth you can pass in a hapi parameter to the moonboots config and it will be added to the config portion of the client app request handler
The app by default will serve on all requests unless you pass in an appPath option
js and css paths will default to appPath if it is defined, and will default to app.js and app.css respectively otherwise.
var Hapi = require('hapi');
var HapiSession = require('hapi-session');
var moonboots_config = {
main: __dirname + '/sample/app/app.js',
developmentMode: false,
libraries: [
__dirname + '/sample/libraries/jquery.js'
],
stylesheets: [
__dirname + '/styles.css'
],
hapi: {
auth: 'session',
},
appPath: '/app'
};
var server = new Hapi.Server();
server.route({
method: 'get',
path: '/',
handler: function (request, reply) {
reply().redirect('/app');
}
});
server.auth('session', {
implementation: new HapiSession(server, session_options)
});
server.pack.require({moonboots_hapi: moonboots_config}, function (err) {
server.start();
});You can also pass in a 'labels' option that will be used to select from hapi which servers will have the moonboots routes added to them (see plugin.select in the hapi docs)
Multiple mooonboots on one server
You can register multiple moonboots apps for a single hapi server like so:
- Pass in an array of moonboots configs instead of a single config.
- Make sure that each config provides unique
appPathor hapi will complain that the paths conflict.
Example of registering multiple apps:
server.pack.require({moonboots_hapi: [moonboots_config1, moonboots_config2]}, function (er) {
server.start();
});Helpers
There are currently two methods exposed from the plugin
server.plugins['moonboots_hapi'].getMoonbootsConfigs(function (configs) {
console.log(configs); //Will be all moonboots configs
});
server.plugins['moonboots_hapi'].getMoonbootsApp(0, function (config) {
console.log(config); //Will be the first moonboots config
});Test
Run npm test
Sample
Run npm start and make sure you have a grey (#ccc) background and the
"Woo! View source to see what rendered me" message in your window.
#License
MIT