nodejs express router to handle authorization and permissioning for ghost express apps


Keywords
ghost, creative
License
ISC
Install
npm install ghost-express-router@1.3.1

Documentation

ghost-express-router

Code Climate Downloads

Router for ghost-express-server.

Install

$ npm install ghost-express-router

Usage

const Config = require('config');
const Joi = require('joi');
const GhostExpressServer = require('ghost-express-server');
const GhostExpressRouter = require('ghost-express-router');
const GhostRouteController = require('ghost-route-controller');
const Router = new GhostExpressRouter();

Router.configure([
  {
    method: 'GET',
    path: '/:id',
    auth: {
      plugin: 'bearerJwt',
      permissions: ['addressSelfFullAccess', 'addressAllFullAccess']
    },
    handler: GhostRouteController.get,
    validate: {
      params: { id: Joi.number().integer() }
    }
  }, {
    method: 'POST',
    path: '/',
    auth: {
      plugin: 'bearerJwt',
      permissions: ['addressSelfFullAccess', 'addressAllFullAccess']
    },
    handler: GhostRouteController.create,
    validate: {
      body: {
        name: Joi.string().required(),
        line1: Joi.string().required(),
        line2: Joi.string(),
        city: Joi.string().required(),
        state: Joi.string().required(),
        zip: Joi.string().regex(/^\d{5}(?:[-\s]\d{4})?$/).required(),
        phone: Joi.string(),
        allerganId: Joi.string()
      }
    }
  }, {
    method: 'PUT',
    path: '/:id',
    auth: {
      plugin: 'bearerJwt',
      permissions: ['addressSelfFullAccess', 'addressAllFullAccess']
    },
    handler: GhostRouteController.update,
    validate: {
      params: { id: Joi.number().integer().required() },
      body: {
        doc: {
          name: Joi.string().required(),
          line1: Joi.string().required(),
          line2: Joi.string(),
          city: Joi.string().required(),
          state: Joi.string().required(),
          zip: Joi.string().regex(/^\d{5}(?:[-\s]\d{4})?$/).required(),
          phone: Joi.string(),
          allerganId: Joi.string(),
          profileId: Joi.number().integer().required()
        }
      }
    }
  }, {
    method: 'DELETE',
    path: '/:id',
    auth: {
      plugin: 'bearerJwt',
      permissions: ['addressSelfFullAccess', 'addressAllFullAccess']
    },
    handler: GhostRouteController.delete,
    validate: {
      params: { id: Joi.number().integer().required() }
    }
  }
]);

GhostExpressServer.create(Config.get('server'))
.then(server => {
    server.useRouter(`/api/v1/addresses`, Router);
    return server
})
.then(server => server.start())