Lumber: The Admin Interface Framework
Lumber is an opensource tool to generate an admin microservice. It serves a REST API hooked directly into your database (MySQL, Postgres and SQL Server for now).
Install
$ npm install -g lumber-cli
NOTICE:
- You may need to use
sudodepending on your platform.
Usage
Quickstart
$ lumber generate
NOTICE:
- Your database credentials are safe. They are only stored in the Lumber generated microservice.
- You may need to use the option
--sslif your database uses a SSL connection. - You can specify the hostname and the port on which your admin will be running
by using the option
--hostnameand--port.
Full demo video: https://www.youtube.com/watch?v=2cKSsBxrvR8
Commands
$ lumber [command]
generategenerate your admin microserviceusershow your current logged userloginsign in to your accountlogoutsign out of your accountactioncreate a new action button on your adminheroku-deploydeploy your admin on production
Advanced
Relationships
As Lumber generates an admin microservice from the database schema, it only
creates belongsTo relationships, based on all your foreign keys.
Please note that some ORMs do not create foreign key constraints. This means
that in some cases, you will have to add belongsTo relationships manually.
Lastly, as databases don't have the notion of inverse relationships, you will
need to add hasMany or hasOne relationships manually.
The generated admin microservice uses the ORM Sequelize. Check out their documentation for advanced model customization.
Adding belongsTo relationships
Open the model file you want in the models directory and declare the
belongsTo relationship in the associate function.
Syntax:
Model.belongsTo(<targetModel>, {
foreignKey: '<foreignKey>',
// ...
));
Available options can be found in the Sequelize documentation.
Example:
module.exports = (sequelize, DataTypes) => {
let models = sequelize.models;
var Model = sequelize.define('users', {
// ...
}, {
classMethods: {
associate: () => {
// BelongsTo relationships
Model.belongsTo(models.addresses);
}
},
// ...
});
return Model;
};Adding inverse of relationships (hasOne, hasMany, …)
Open the model file you want in the models directory and declare the
hasMany (hasOne is very similar) relationship in the associate function.
Syntax:
Model.hasMany(<targetModel>, {
// [options]
// ...
));Available options can be found in the Sequelize documentation.
module.exports = (sequelize, DataTypes) => {
let models = sequelize.models;
var Model = sequelize.define('users', {
// ...
}, {
classMethods: {
associate: () => {
// hasMany relationships
Model.hasMany(models.books);
// hasOne relationships
Model.hasOne(models.car);
}
},
// ...
});
return Model;
};Actions
Common actions such as CRUD, sort or search are implemented by default. You will probably want to provide your admin with actions to perform operations that are specific to your application. Moderating comments, logging into a customer’s account (a.k.a impersonate) or banning a user are typical examples of specific actions.
The following command will automatically generate an approve action on
the comments collection.
$ lumber action comments approve
Declaration: /forest/comments.js
'use strict';
var liana = require('forest-express-sequelize');
liana.collection('comments', {
actions: [
{ name: 'approve' },
]
});Implementation: /routes/comments.js (customize the business logic here).
'use strict';
var express = require('express');
var router = express.Router();
var liana = require('forest-express-sequelize');
router.post('/actions/approve', liana.ensureAuthenticated,
(req, res) => {
// Your business logic here.
res.send({
success: 'Comments successfully approved!'
});
});
module.exports = router;Deploy to production
Deploying your admin to a custom server
Simply run $ lumber deploy -c and follow the instructions.
Watch video:
Deploying your admin to Heroku
Lumber provides the command heroku-deploy to push your local admin interface
to your Production environment.
- Create a new Github repository.
- Push your generated admin microservice on your new Github repository.
- Ensure you have a Heroku (free) account and the Heroku CLI installed.
- Login to your Heroku account using the command-line:
$ heroku login. 🎉 Deploy your admin microservice on production:$ lumber heroku-deploy -c.🎉



