JSPM

  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q49022F

Moonboots plugin that allows it to serve files using a hapi server

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.

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

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 () {
        this.reply.redirect('/app').message('Redirecting to clientside app...');
    }
});
server.auth('session', {
    implementation: new HapiSession(server, session_options)
});

server.pack.require({moonboots_hapi: moonboots_config}, function (err) {
    server.start();
});

Test

For now, run sample.js 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