Skip to content

HenrikJoreteg/moonboots-hapi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();
});

Multiple mooonboots on one server

You can register multiple moonboots apps for a single hapi server like so:

  1. Pass in an array of moonboots configs instead of a single config.
  2. Make sure that each config provides unique appPath or 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();
});

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

About

Hapi plugin for moonboots

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.8%
  • CSS 0.2%