Skip to content

Commit

Permalink
published 0.6.7
Browse files Browse the repository at this point in the history
  - Added request tracing
  • Loading branch information
jonrobins committed Feb 15, 2018
1 parent c664e1e commit 2dce4c3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ app.use(micro([options]));
- `monitorsPath`: `String` Path to load monitors. Defaults to `monitors`.
- `partialResponseQuery`: `String` The query parameter to use for partial reponse. Defaults to `fields`.
- `correlationHeaderName`: `String` The name of your correlation header. Defaults to `X-CorrelationID`.
- `enableBodyParsing`: `boolean` Enable or disable body parsing, useful to disable when dealign with content other than JSON. Enables express-validator. Defaults to `true`.
- `enableBodyParsing`: `boolean` Enable or disable body parsing, useful to disable when dealing with content other than JSON. Enables express-validator. Defaults to `true`.
- `validatorOptions`: `object` Enable express-validator with these options. Defaults to `null`.
- `etag`: `boolean` Activate etag.
- `requestTracing`: `boolean` Enabled request log trace. Defaults to `false`.

## SWAGGER Integration

Expand Down
3 changes: 2 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ app.use(micro({
discoverable: true,
debug: true,
controllersPath: './controllers',
monitorsPath: './monitors'
monitorsPath: './monitors',
requestTracing: true
}));

app.on('service:registered', function (data) {
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var buildOptions = function(options) {
options.enableBodyParsing = options.enableBodyParsing || true;
options.validatorOptions = options.validatorOptions || null;
options.etag = options.etag || false;
options.requestTracing = options.requestTracing || false;

// Return now if we have no config
if (!config.app) {
Expand Down
30 changes: 18 additions & 12 deletions lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
/*
* Dependencies
*/
var path = require('path');
var fs = require('fs');
var enrouten = require('express-enrouten');
var bodyParser = require('body-parser');
var cors = require('cors');
var cache = require('express-cache-response-directive');
var zoologist = require('./zoologist');
var log = require('./logger');
var partialRes = require('express-partial-response');
var validator = require('express-validator');
var correlate = require('./middleware/correlate');
var swagger = require('./swagger');
var path = require('path');
var fs = require('fs');
var enrouten = require('express-enrouten');
var bodyParser = require('body-parser');
var cors = require('cors');
var cache = require('express-cache-response-directive');
var zoologist = require('./zoologist');
var log = require('./logger');
var partialRes = require('express-partial-response');
var validator = require('express-validator');
var correlate = require('./middleware/correlate');
var requestTracing = require('./middleware/request-tracing');
var swagger = require('./swagger');

/**
* Bootstrap the microservice.
Expand Down Expand Up @@ -56,6 +57,11 @@ module.exports = function (app, options) {
// Correlation
app.use(correlate({ headerName: options.correlationHeaderName }));

// Enable request Tracing
if (options.requestTracing) {
app.use(requestTracing);
}

// Starter routes (e.g. actuator)
app.use('/' + options.serviceName, enrouten({ directory: '../controllers' }));

Expand Down
19 changes: 19 additions & 0 deletions lib/middleware/request-tracing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const ip = require('request-ip');

/**
* Middleware to Log Request Detail
*/
module.exports = function(req, res, next) {

var meta = {
request: {
client: {ip: ip.getClientIp(req)},
method: req.method,
path: req.originalUrl,
headers: req.headers
}
};

req.log.info(meta, 'Request Trace');
next();
};
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "express-microservice-starter",
"version": "0.6.6",
"version": "0.6.7",
"description": "An express-based Node.js API bootstrapping module for microservices.",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test ./node_modules/.bin/mocha 'test/**/*.test.js'",
"test": "NODE_ENV=test ./node_modules/.bin/mocha 'test/**/*.test.js'",
"security": "node ./node_modules/nsp/bin/nsp check --output checkstyle"
},
"repository": {
Expand Down Expand Up @@ -40,6 +40,7 @@
"ip": "1.1.5",
"konfig": "0.2.1",
"optional": "0.1.4",
"request-ip": "2.0.2",
"swagger-tools": "0.10.3",
"uuid": "3.1.0",
"vitalsigns": "0.4.3",
Expand Down

0 comments on commit 2dce4c3

Please sign in to comment.