Skip to content

Commit

Permalink
Merge 5c05845 into 5b26946
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Jun 18, 2018
2 parents 5b26946 + 5c05845 commit 8b60809
Show file tree
Hide file tree
Showing 135 changed files with 17,934 additions and 5,939 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -15,4 +15,6 @@ config/config.production.json

workspace/media/*

test/acceptance/temp-workspace

scripts/coverage.svg
4 changes: 2 additions & 2 deletions README.md
@@ -1,7 +1,7 @@
<img src="https://dadi.cloud/assets/products/dadi-api-full.png" alt="DADI API" height="65"/>

[![npm (scoped)](https://img.shields.io/npm/v/@dadi/api.svg?maxAge=10800&style=flat-square)](https://www.npmjs.com/package/@dadi/api)
[![coverage](https://img.shields.io/badge/coverage-88%25-yellow.svg?style=flat)](https://github.com/dadi/api)
[![coverage](https://img.shields.io/badge/coverage-89%25-yellow.svg?style=flat)](https://github.com/dadi/api)
[![Build Status](https://travis-ci.org/dadi/api.svg?branch=master)](https://travis-ci.org/dadi/api)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)

Expand Down Expand Up @@ -35,7 +35,7 @@ It is part of DADI, a suite of components covering the full development stack, b

### Install API

The quickest way to get started with *API* is to use [DADI CLI](https://github.com/dadi/cli). See [Creating an API](https://docs.dadicloud/api) for full installation details.
The quickest way to get started with *API* is to use [DADI CLI](https://github.com/dadi/cli). See [Creating an API](https://docs.dadi.cloud/api#creating-an-api) for full installation details.


### Configuration
Expand Down
33 changes: 19 additions & 14 deletions config.js
Expand Up @@ -86,46 +86,51 @@ var conf = convict({
}
},
datastore: {
doc: '',
doc: 'The name of the npm module that implements the data connector used for storing documents',
format: String,
default: '@dadi/api-mongodb'
},
auth: {
tokenUrl: {
doc: '',
doc: 'The endpoint used for token generation',
format: String,
default: '/token'
},
tokenTtl: {
doc: '',
doc: 'The amount of time (in seconds) which bearer tokens are valid for',
format: Number,
default: 1800
},
tokenKey: {
doc: 'The private key used to sign JWT tokens',
format: String,
default: 'YOU-MUST-CHANGE-ME!'
},
accessCollection: {
doc: 'The name of the internal collection used to store aggregate permissions data',
format: String,
default: 'accessStore'
},
clientCollection: {
doc: '',
doc: 'The name of the internal collection used to store clients',
format: String,
default: 'clientStore'
},
tokenCollection: {
doc: '',
roleCollection: {
doc: 'The name of the internal collection used to store roles',
format: String,
default: 'tokenStore'
default: 'roleStore'
},
datastore: {
doc: '',
doc: 'The name of the npm module that implements the data connector used for authentication',
format: String,
default: '@dadi/api-mongodb'
},
database: {
doc: '',
doc: 'The name of the database used to store authentication data',
format: String,
default: 'test',
env: 'DB_AUTH_NAME'
},
cleanupInterval: {
doc: 'The interval (in seconds) at which the token store will delete expired tokens from the database',
format: Number,
default: 3600
}
},
caching: {
Expand Down
8 changes: 4 additions & 4 deletions config/config.test.json.sample
Expand Up @@ -32,9 +32,9 @@
}
},
"paths": {
"collections": "test/acceptance/workspace/collections",
"endpoints": "test/acceptance/workspace/endpoints",
"hooks": "test/acceptance/workspace/hooks"
"collections": "test/acceptance/temp-workspace/collections",
"endpoints": "test/acceptance/temp-workspace/endpoints",
"hooks": "test/acceptance/temp-workspace/hooks"
},
"logging": {
"enabled": true,
Expand All @@ -45,7 +45,7 @@
},
"media": {
"defaultBucket": "mediaStore",
"basePath": "test/acceptance/workspace/media"
"basePath": "test/acceptance/temp-workspace/media"
},
"feedback": false,
"cors": false,
Expand Down
21 changes: 21 additions & 0 deletions dadi/lib/api/index.js
Expand Up @@ -98,6 +98,27 @@ Api.prototype.use = function (path, handler) {
}
}

/**
* Connects a set of handlers, one per HTTP verb, to
* a given path.
*
* @param {String} path
* @param {Object} handlers
* @return undefined
* @api public
*/
Api.prototype.routeMethods = function (path, handlers) {
return this.use(path, function (req, res, next) {
let method = req.method && req.method.toLowerCase()

if (typeof handlers[method] === 'function') {
return handlers[method](req, res, next)
}

next()
})
}

/**
* Removes a handler or removes the handler attached to a specific path
* @param {String} path
Expand Down

0 comments on commit 8b60809

Please sign in to comment.