Giter Club home page Giter Club logo

trailpack-router's Introduction

trailpack-router

Gitter NPM version Build status Dependency Status Code Climate Follow @trailsjs on Twitter

Trailpack Router. Aggregates all routes from config.routes and attaches prerequisites (Policies) to form hapi.js route objects.

Usage

Load from your trailpack config. (This pack is included by default).

// config/main.js
module.exports = {
  // ...
  packs: [
    require('trailpack-core'),
    require('trailpack-router')
  ]
}

Configure

config.policies

The policies configuration maps controller handlers to a list of policies which must pass before the handler is invoked.

// config/policies.js
module.exports = {
  '*': [ 'GlobalPolicy.test' ],  // Apply GlobalPolicy.test to all handler except the ones below
  ExampleController: {
    test: [ 'ExamplePolicy.test' ]
  },
  Example2Controller: [ 'ExamplePolicy.test' ], // Apply ExamplePolicy.test to all handler
  Example3Controller: {
    '*': [ 'GlobalExample3Policy.test' ], // Apply GlobalExample3Policy.test to all handler except the ones below
    test: [ 'OverridePolicy.test' ]
  }
}

config.routes

The list of route objects to be compiled for use by the webserver.

// config/routes.js
module.exports = [
  {
    method: [ 'GET' ],
    path: '/example/test',
    handler: 'ExampleController.test'
  }
]

During initialization, for the above example, a route object will be compiled that takes the following form:

  {
    method: [ 'GET' ],
    path: '/example/test',
    handler: 'ExampleController.test',
    config: {
      pre: [ 'ExamplePolicy.test' ]
    }
  }

Compatible Trailpacks

Contributing

We love contributions! Please see our Contribution Guide for more information.

License

MIT

trailpack-router's People

Contributors

greenkeeperio-bot avatar jaumard avatar konstantinzolotarev avatar thejones avatar tjwebb avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.