grunt-hapify

0.3.0 • Public • Published

grunt-hapify Build Status

Start a hapi server

Includes console logging plugin through good-console.

Note that this server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. This behavior can be changed with the keepalive option.

This task was designed to be used in conjunction with another task that is run immediately afterwards, like the grunt-contrib-watch plugin watch task.

You can run this task with the grunt hapify command.

Install

$ npm install --save-dev grunt-hapify

Usage

grunt.loadNpmTasks('grunt-hapify');
 
grunt.initConfig({
 
    hapify: {
        server: {
            options: {
                keepalive: true, // set to false if in conjunction with watch
 
                // Override default port / Hapi `connection` object
                connection: {
                    port: 9002
                },
 
                // Override default plugin options
                visionary: {
                    engine: {
                        tag: 'hapi-riot'
                    }
                    path: '/path/to/views'
                },
 
                // Override default plugin options
                good: {
 
                    myHTTPReporter: [{
                        module: 'good-squeeze',
                        name: 'Squeeze',
                        args: [{ error: '*' }]
                    }, {
                        module: 'good-http',
                        args: ['http://prod.logs:3000', {
                            wreck: {
                                headers: { 'x-api-key': 12345 }
                            }
                        }]
                    }]
                },
 
                // Add new routes
                routes: [
 
                    // File path accepted
                    'routes/*.js',
 
                    // Array of file paths accepted
                    ['routes/*.js', 'more-routes/**/*.js'],
 
                    // Path object accepted
                    { path: '/foo', method: 'get', handler: (request, reply) => { reply('bar'); }},
 
                    // Array of path objects accepted
                    [{ path: '/come', method: 'get', handler: (request, reply) => { reply('some'); }}]
                ],
 
                // Add new plugins
                plugins: [
 
                    // File path accepted
                    'plugins/*.js',
 
                    // Array of file paths accepted
                    ['plugins/*.js', 'more-plugins/**/*.js'],
 
                    // Plugin function accepted
                    require('Nes'),
 
                    // Array of path objects accepted
                    [require('Joi'), require('hapi-auth-basic')]
                ]
            }
        }
    }
});
 
grunt.registerTask('default', ['hapify']);

Defaults

Default plugins are Good, Visionary, Blipp, and Inert. This gives us routes logging support, template rendering support, and static file serving. Default plugin configs can be overwritten my passing: { nameOfDefaultPlugin: { ..config } } For example: { visionary: { path: './assets' } }

Options

keepalive

Type: Boolean Default: false

Keep the server alive indefinitely. Note that if this option is enabled, any tasks specified after this task will never run. By default, once grunt's tasks have completed, the web server stops. This option changes that behavior.

server

Type: Object Default: { debug: false }

Options used to initialize the hapi serve (new Hapi.Server(<server>)).
See hapi server options for more info

connection

Type: Object Default: { port: 9090, routes: { cors: true } }

Options used to start a connection (server.connection(<connection>)).
See hapi connection options for more info.

routes

Type: Array Default: { path: '/', method: 'get', handler: function (req, rep) { return rep('Grunt Hapify'); } }

Server routes to load on the server (server.route(<routes>)).
See hapi routes for more info.

plugins

Type: Array Default: Good Plugin

Hapi plugins to load on the server (server.register(<plugins>)).
See hapi plugins for more info.

Todo

  • Support Livereload

Done

  • Serve static files using inert
  • Render templates using vision

Contributing

Readme

Keywords

Package Sidebar

Install

npm i grunt-hapify

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

63.8 kB

Total Files

8

Last publish

Collaborators

  • genediazjr