cloudant-envoy
Advanced tools
Comparing version 0.3.0 to 0.3.1
23
app.js
@@ -33,3 +33,2 @@ 'use strict'; | ||
// Setup the logging format | ||
@@ -41,6 +40,9 @@ if (app.opts.logFormat !== 'off') { | ||
function main() { | ||
// plug in custom routes | ||
if (app.opts.router) { | ||
app.use(app.opts.router); | ||
// Load custom middleware | ||
if (app.opts.middleware.length) { | ||
console.log('[OK] Loading middleware'); | ||
app.opts.middleware.forEach(function(m) { | ||
app.use(m); | ||
}); | ||
} | ||
@@ -58,7 +60,7 @@ | ||
// enable cors | ||
app.use(cors()); | ||
app.use(cors()); | ||
// gzip responses | ||
app.use(compression()); | ||
app.use(bodyParser.json({ limit: '50mb'})); | ||
@@ -79,2 +81,7 @@ app.use(bodyParser.urlencoded({ extended: false, limit: '50mb' })); | ||
// plug in custom routes | ||
if (app.opts.router) { | ||
app.use(app.opts.router); | ||
} | ||
// load the routes | ||
@@ -131,3 +138,1 @@ var router = require('./lib/routes/index'); | ||
}; | ||
@@ -18,3 +18,4 @@ 'use strict'; | ||
static: process.env.ENVOY_STATIC || startOpts.static || null, | ||
router: startOpts.router || null | ||
router: startOpts.router || null, | ||
middleware: startOpts.middleware || [] | ||
}; | ||
@@ -21,0 +22,0 @@ |
{ | ||
"name": "cloudant-envoy", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "A mobile backend shim to Cloudant", | ||
@@ -33,3 +33,3 @@ "contributors": [ | ||
"cfenv": "^1.0.3", | ||
"cloudant": "^1.5.1", | ||
"cloudant": "^1.6.2", | ||
"compression": "^1.6.2", | ||
@@ -39,3 +39,3 @@ "express": "^4.14.0", | ||
"morgan": "^1.7.0", | ||
"request": "^2.76.0", | ||
"request": "^2.78.0", | ||
"uuid": "^2.0.3" | ||
@@ -42,0 +42,0 @@ }, |
@@ -182,2 +182,25 @@ # Cloudant Envoy (beta) | ||
### Custom middleware | ||
You can supply your own custom middleware to Envoy | ||
```js | ||
var myLogger = function (req, res, next) { | ||
console.log('LOGGED') | ||
next() | ||
}; | ||
var opts = { | ||
databaseName: dbName, | ||
port: appEnv.port, | ||
logFormat: 'dev', | ||
production: true, | ||
static: path.join(__dirname, './public'), | ||
router: router, | ||
middleware: [myLogger] | ||
}; | ||
var envoy = require('envoy')(opts); | ||
``` | ||
The `middleware` property expects an array of Express middleware functions. | ||
## Debugging | ||
@@ -184,0 +207,0 @@ |
353232
4419
326
Updatedcloudant@^1.6.2
Updatedrequest@^2.78.0