hapi-router
Advanced tools
Comparing version 3.0.1 to 3.2.0
@@ -1,6 +0,4 @@ | ||
'use strict'; | ||
'use strict' | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var glob = require('glob'); | ||
var glob = require('glob') | ||
@@ -15,14 +13,24 @@ exports.register = function (server, options, next) { | ||
var files = glob.sync(options.routes, globOptions); | ||
var patterns = [] | ||
files.forEach(function (file) { | ||
server.route(require(globOptions.cwd + '/' + file)); | ||
}); | ||
if (options.routes.constructor === Array) { | ||
patterns = options.routes | ||
} else { | ||
patterns = [ options.routes ] | ||
} | ||
next(); | ||
}; | ||
patterns.forEach(function (pattern) { | ||
var files = glob.sync(pattern, globOptions) | ||
files.forEach(function (file) { | ||
server.route(require(globOptions.cwd + '/' + file)) | ||
}) | ||
}) | ||
next() | ||
} | ||
exports.register.attributes = { | ||
multiple: false, | ||
pkg: require('../package.json') | ||
}; | ||
} |
{ | ||
"name": "hapi-router", | ||
"version": "3.0.1", | ||
"version": "3.2.0", | ||
"description": "Opinionated route loader for hapi", | ||
"main": "./lib", | ||
"scripts": { | ||
"test": "istanbul cover _mocha --" | ||
"test": "standard && istanbul cover _mocha --" | ||
}, | ||
@@ -28,8 +28,9 @@ "repository": { | ||
"chai-as-promised": "^4.1.1", | ||
"hapi": "^8.0.0", | ||
"hapi": "8 || 9", | ||
"istanbul": "^0.3.2", | ||
"mocha": "^2.0.1" | ||
"mocha": "^2.0.1", | ||
"standard": "^5.2.1" | ||
}, | ||
"peerDependencies": { | ||
"hapi": "^8.0.0" | ||
"hapi": "8 || 9" | ||
}, | ||
@@ -36,0 +37,0 @@ "dependencies": { |
@@ -1,2 +0,3 @@ | ||
#hapi-router | ||
# hapi-router | ||
[![Build Status](https://travis-ci.org/bsiddiqui/hapi-router.svg?branch=master)](https://travis-ci.org/bsiddiqui/hapi-router) [![Code Climate](https://codeclimate.com/github/bsiddiqui/hapi-router/badges/gpa.svg)](https://codeclimate.com/github/bsiddiqui/hapi-router) [![Test Coverage](https://codeclimate.com/github/bsiddiqui/hapi-router/badges/coverage.svg)](https://codeclimate.com/github/bsiddiqui/hapi-router) [![Version](https://badge.fury.io/js/hapi-router.svg)](http://badge.fury.io/js/hapi-router) [![Downloads](http://img.shields.io/npm/dm/hapi-router.svg)](https://www.npmjs.com/package/hapi-router) | ||
@@ -6,3 +7,3 @@ | ||
## Setup | ||
## Install | ||
@@ -13,5 +14,7 @@ ```bash | ||
## Usage | ||
```js | ||
server.register({ | ||
register: require('hapi-router') | ||
register: require('hapi-router'), | ||
options: { | ||
@@ -27,11 +30,24 @@ routes: 'src/**/*Route.js' // uses glob to include files | ||
The following required `options` should be provided at registration: | ||
* `routes`: the [glob](https://github.com/bsiddiqui/hapi-router#glob-primer) pattern you would like to include | ||
##### routes | ||
The following optional `options` can be provided at registration: | ||
* `ignore`: the pattern or an array of patterns to exclude | ||
* `cwd`: the current working directory in which to search (defaults to `process.cwd()`) | ||
*Required* <br/> | ||
Type: `string` / `array` | ||
The [glob](https://github.com/bsiddiqui/hapi-router#glob-primer) 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 | ||
@@ -60,2 +76,10 @@ | ||
## Glob Primer | ||
Example globs: | ||
```js | ||
'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](https://github.com/isaacs/node-glob): | ||
@@ -86,8 +110,1 @@ | ||
It does not crawl symlinked directories. | ||
Example globs: | ||
```js | ||
'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' | ||
``` |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5614
27
106
1
6