8000 GitHub - fabrix-app/spool-router at v1.1.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fabrix-app/spool-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spool-router

Gitter NPM version Build Status Test Coverage Dependency Status Follow @FabrixApp on Twitter

Spool Router. Aggregates all routes from config.routes to create hapi.js route objects.

Install

$ npm install @fabrix/spool-router --save

Usage

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

// config/main.js
module.exports = {
  // ...
  spools: [
    require('spool-router').Router
  ]
}

Configure

config.router

The Router takes a few Configuration values

// config/router.ts
export const router = {
  sortOrder: 'asc', // (asc | desc)
  prefix: '/api/v1'
}
router.sortOrder

This will sort the routes based on the key (path) either ascending or descending. This is used in spools like Express where the order of routes matters.

router.prefix

This config is optional and can be left as ''. This will prefix each route with the specified prefix.

config.routes

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

// config/routes.ts
const routes = {
  '/example/test': {
    'GET': 'ExampleController.test'
  }
}

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

{
  // ...
  '/example/test': {
    'GET': 'ExampleController.test',
    config: {
      pre: [ 'ExamplePolicy.test' ]
    }
  }
  // ...
}
{
  // ...
  '/example/test': {
    'GET': 'ExampleController.test',
    config: {
      prefix: '/api/v2'
    }
  }
  // ...
}

The Configuration above, will give this route a prefix of /api/v2 instead of using the config.prefix that was specified

Optionally:

{
  // ...
  '/example/test': {
    'GET': 'ExampleController.test',
    config: {
      prefix: false
    }
  }
  // ...
}

The Configuration about, will ignore any prefix given to it.

Optionally:

{
  // ...
  '/example/test': {
    'GET': 'ExampleController.test',
    config: {
      prefix: 'customPrefixer.prefix'
    }
  }
  // ...
}

The configuration above will take the configuration of another config attribute, in this case: app.config.customPrefixer.prefix is set to /custom/endpoint so the resulting route prefix will be /custom/endpoint/example/test

Tapestries and Policies

Support for tapestries and Policies is provided by spool-tapestries.

Compatible Spools

Contributing

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

License

MIT

Packages

No packages published

Contributors 2

  •  
  •  
0