Newman's Personal Motorcade

    @ntlab/express-middleware

    1.1.0 • Public • Published

    Nodejs Express Middleware

    Nodejs Express Middleware is a set of middlewares build for Expressjs aimed at:

    • Support layout rendering.
    • Provide block and slot mechanism to include views in Expressjs (block and slot helper).
    • Provide NODE-NTJS script integration (script, scripts, javascripts, stylesheets, and jsloader helper).
    • Provide menu builder (menu helper).
    • Provide pager builder (pager helper).
    • Provide a simple security to Expressjs routes (user helper).

    Expressjs Integration

    Here is a typical usage in Expressjs app.

    // app.js
    
    // security
    app.use(require('./lib/security/security')());
    
    // app helpers
    app.use(require('./lib/helper/core')());
    app.use(require('./lib/helper/menu')());
    app.use(require('./lib/helper/pager')());
    
    const { ScriptManager, ScriptAsset } = require('./lib/script');
    ScriptManager.addDefault('SemanticUI');
    ScriptManager.addAsset(ScriptAsset.STYLESHEET, 'app.css');
    
    // relative from layout
    app.slots = {
      mainmenu: {
        view: '../slot/mainmenu'
      }
    };
    <%# mainmenu.ejs %>
    
    <% menus = {
        branding: {
            type: 'brand',
            title: apptitle,
            logo: '/images/logo.png',
            url: '/'
        },
        tasks: {
            title: 'Tasks',
            class: 'right floated',
            items: {
                about: {
                    title: 'About'
                }
            }
        }
    } %>
    <% if(user.authenticated) {
        Object.assign(menus.tasks.items, {
            divider1: {
                type: 'divider'
            },
            profile: {
                title: 'Profile'
            }
        });
    } %>
    <%- menu(menus, {mainmenu: true, indentation: 2}) %>
    <% script.create('JQuery')
      .useDependencies(['SemanticUI/Dialog/Message'])
      .addMiddle(`
    $.tasks = {
        about: function() {
            $.ntdlg.message('task-about', 'About', 'About App Message', $.ntdlg.ICON_INFO);
        },
        profile: function() {
            $.ntdlg.message('task-profile', 'Howdy', 'Welcome User', $.ntdlg.ICON_INFO);
        },
        init: function() {
            var self = this;
            $('.menu-about').on('click', function(e) {
                e.preventDefault();
                self.about();
            });
            $('.menu-profile').on('click', function(e) {
                e.preventDefault();
                self.profile();
            });
        }
    }
    `).addLast(`
    $.tasks.init();
    `); %>

    Example Usage

    Nodejs Express Middleware is heavily used by NODE-SMS-TERMINAL and NODE-SMS-GATEWAY.

    Install

    npm i @ntlab/express-middleware

    DownloadsWeekly Downloads

    6

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    23.6 kB

    Total Files

    8

    Last publish

    Collaborators

    • tohenk