Socket
Socket
Sign inDemoInstall

hapi-router

Package Overview
Dependencies
2
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hapi-router

Opinionated route loader for hapi


Version published
Weekly downloads
551
increased by14.79%
Maintainers
1
Install size
151 kB
Created
Weekly downloads
 

Readme

Source

hapi-router

Build Status Code Climate Test Coverage Version Downloads

Route loader for hapi.

Hapi v17

hapi-router requires Hapi v18.

  • Hapi 18, hapi-router@5
  • Hapi 17, hapi-router@4
  • Hapi <= 16, hapi-router@3

Install

// If you're using Hapi v18
$ npm i -S hapi-router@5

// If you're using Hapi v17
$ npm i -S hapi-router@4

// If you're using < Hapi v17
$ npm i -S hapi-router@3.5.0

Usage

try {
  await server.register({
    plugin: require('hapi-router'),
    options: {
      routes: 'src/**/*Route.js' // uses glob to include files
    }
  })
} catch (err) {
  // Handle err
  throw err
}

Options

routes

Required
Type: string / array

The glob pattern you would like to include

ignore

Type: string / array

The pattern or an array of patterns to exclude

cwd

Type: string

The current working directory in which to search (defaults to process.cwd())

Specifying Routes

Any files that match your routes glob will be loaded

Example route file:

module.exports = [
  {
    path: '/test1',
    method: 'GET',
    handler: function (request, reply) {
      reply('hello');
    }
  },
  {
    path: '/test2',
    method: 'GET',
    handler: function (request, reply) {
      reply('hello');
    }
  }
]

Glob Primer

Example globs:

'routes/*.js'    // match all js files in the routes directory
'routes/**/*.js' // recursively match all js files in the routes directory
'**/*Route.js'   // match all js files that end with 'Route'

From isaacs:

"Globs" are the patterns you type when you do stuff like ls *.js on the command line, or put build/* in a .gitignore file.

The following characters have special magic meaning when used in a path portion:

  • * Matches 0 or more characters in a single path portion
  • ? Matches 1 character
  • [...] Matches a range of characters, similar to a RegExp range. If the first character of the range is ! or ^ then it matches any character not in the range.
  • !(pattern|pattern|pattern) Matches anything that does not match any of the patterns provided.
  • ?(pattern|pattern|pattern) Matches zero or one occurrence of the patterns provided.
  • +(pattern|pattern|pattern) Matches one or more occurrences of the patterns provided.
  • *(a|b|c) Matches zero or more occurrences of the patterns provided
  • @(pattern|pat*|pat?erN) Matches exactly one of the patterns provided
  • ** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.

Keywords

FAQs

Last updated on 12 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc