@ntlab/express-middleware
v2.2.0
Published
Nodejs Express Middleware
Downloads
6
Readme
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
andslot
helper). - Provide NODE-NTJS script integration
(
script
,scripts
,javascripts
,stylesheets
, andjsloader
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.