police-control
v1.0.2
Published
Controller and policy implementation for express.js
Downloads
5
Maintainers
Readme
The documentation will hopefully be more elaborated one day...
Usage
app.js
var express = require('express');
var app = express();
var policeControl = require('police-control');
var router = policeControl.Router;
// These are the default values
var options = {
routes: './config/routes',
policies: './config/policies',
controllerPath: './controllers',
policyPath: './policies'
};
Router.setup(app, options);
config/routes.js
module.exports = { // Route definition example
api: { // /api
v1: { // /v1/api
users: { // /v1/api/users
'GET /': 'UsersController.index', // route for /api/v1/users
'GET /:id': 'UsersController.show',
'POST /': 'UsersController.create',
'PUT /:id': 'UsersController.update',
'DELETE /:id': 'UsersController.destroy'
}
}
}
};
config/policies.js
module.exports = { // Policy definition example
UsersController: {
'*': 'isLoggedIn', // default policy for UsersController
'create': null, // override default 'isLoggedIn' for 'create' action
'update': ['canUpdate']
},
AnotherController: 'isLoggedIn' // apply to all actions in AnotherController
};