Nanoscale Parts Manufacturing

    This package has been deprecated

    Author message:

    Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

    feliz

    0.0.17 • Public • Published

    Hapi Rx

    A minimalistic wrapper for hapi.js to build servers

    Usage

    index.js

    'use strict'
    const HapiRx = require('hapi-rx');
    
    const server$ = HapiRx({
        root: './app',
    });
    
    server$.subscribe(
        hapirx => console.log('Server running.'),
        err    => { throw err; }
    )
    

    app/routes.js

    'use strict';
    
    const Joi = require('joi');
    
    module.exports = {
    
        '/{id?}': {
            method: 'GET',
            bundle: 'root',
            config: {
                cache: false,
                validate: {
                    params:{
                        id: Joi.string().regex(/[a-f0-9]{24}/)
                    }
                }
            }
        },
    
        'action':{
            method: 'SOCKET',
            bundle: 'socket'
        },
    
    }
    

    app/bundles/root/index.js

    'use strict'
    
    module.exports = (request, reply){
        let path = this.path.bundles; // Access to the server instance
        if (request.params.id) return reply(`Hello ${request.params.id}`);
        reply('Hello world');
    }
    

    app/bundles/socket.js

    'use strict'
    // Still in alpha
    module.exports = (type, data){
        // emited using channel: socket:test
        if (type == 'test'){
            // do something with data
        }
    }
    

    Install

    npm i feliz

    DownloadsWeekly Downloads

    4

    Version

    0.0.17

    License

    MIT

    Last publish

    Collaborators

    • etor